6.4 관계 연산자 Relational Operators

공기훈·2021년 9월 7일
0

홍정모의 따배씨

목록 보기
29/49
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>	// fabs()
int main()
{
	/*
		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
	*/

	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++);

1 2 3 4 5 출력
A B C D ... X Y 출력

	const double PI = 3.14159265358979;
	double guess = 0.0;

	printf("Input pi : ");
	scanf("%lf", &guess);;
	while (guess < PI)
	{
		printf("Fool! Try again.\n");
		scanf("%lf", &guess);
	}

	printf("Good!");

while (fabs(guess - PI) > 0.01)
fabs() 는 절댓값을 출력해내는 함수이다.
#include <math.h>를 입력해야지 사용할 수 있다.

profile
be a coding master

0개의 댓글