두 표현을 비교할 때 사용합니다.
| 연산자 | 설명 | 예 | a=10,b=20 | 출력 |
|---|---|---|---|---|
| < | 미만 | a | 10<20 | 1 |
| <= | 보다 작거나 같음 | a<=b | 10<=20 | 1 |
| > | 보다 큼 | 나 | 10>20 | 0 |
| >= | 보다 큼(또는) 같음 | a>=b | 10>=20 | 0 |
| == | 같음 | a==b | 10==20 | 0 |
| != | 같지 않음 | a!=b | 10!=20 | 1 |
관계식 출력은 참(1)(또는) 거짓(0)입니다.
알고리즘
아래 주어진 알고리즘을 따르십시오 -
START Step 1: Declare integer variables. Step 2: Read all variables at runtime. Step 3: Perform relational operations. i. a<b ii. a<=b iii. a>b iv. a>=b v. a==b vi. a!=b Step 4: Print all computed values.
예시
다음은 관계 연산자를 계산하는 C 프로그램입니다 -
#include<stdio.h>
main (){
int a,b;
printf("enter a,b values:\n");
scanf("%d%d",&a,&b);
printf("%d\n",a<b);
printf("%d\n",a<=b);
printf("%d\n",a>b);
printf("%d\n",b>=a);
printf("%d\n",a==b);
printf("%d\n",a!=b);
} 출력
다음 출력이 표시됩니다 -
enter a,b values: 120 340 1 1 0 1 0 1