홍정모의 따라하며 배우는 C언어 정리

관계 연산자

채고루 2023. 3. 14. 23:55

- Relational Operators
<         is less than
<=        is less than or equal to
==        is equal to
>=        is greater than or equal to
>         is greater than
!=        is not equal to

 

#include <stdio.h>
#include <math.h>  // fabs(): 절댓값
int main()
{
  int n = 0;
  while (n++ < 5)  // n++ < 5 is a relational expression
  printf("%d", n);

  printf("\n");

  char c = 'A';
  while (c != 'Z')
  printf("%c", c++);

  const double PI = 3.1415926535897832384626433832795;
  double guess = 0.0;

  printf("Input pi: ");
  scanf("%1f", &guess);;
// while (guess != PI) -> 이렇게 할 경우 정확한 값만을 입력해야 결과값 도출
  while (fabs(guess-PI) > 0.01) // 적당한 선에서 조절을 하기 위한 방식, 오차 범위의 절댓값이 0.01보다 클 때 성립
{
  printf("Fool! Try again.\n");
  scanf("%1f", &guess);
}

  printf("Good!");

return 0;
}

'홍정모의 따라하며 배우는 C언어 정리' 카테고리의 다른 글

_Bool 자료형  (0) 2023.03.15
사실과 거짓  (0) 2023.03.15
while 반복 루프에서 scanf()의 반환값 사용하기  (0) 2023.03.14
자료형 변환  (0) 2023.03.14
증가, 감소 연산자  (0) 2023.03.08