*if (조건문) 실행문; - 조건이 참이면 문장을 실행한다.
*0이 아닌 값은 참, 0은 무조건 거짓
*관계연산자 <(크다), >(작다), ==(같다), <=(크거나같다), >=,(작거나같다)
p.72
#include <stdio.h>
int main(void)
{
int num;
printf("enter a number: ");
scanf("%d", &num);
if(num<0) printf("number is negative.");
if(num>-1) printf("number is non-negative.");
return 0;
}
p.72_예제1
#include <stdio.h>
int main(void)
{
int answer;
printf("What is 10+14? ");
scanf("%d", &answer);
if(answer == 10+14) printf("Right!");
return 0;
}
p.73_예제2
#include <stdio.h>
int main(void)
{
float num;
int choice;
printf("enter value: ");
scanf("%f", &num);
printf("1: feet to meters, 2: meters to feet ");
printf("enter choice: ");
scanf("%d", &choice);
if(choice == 1) printf("%f", num/3.28);
if(choice == 2) printf("%f", num*3.28);
return 0;
}
p.73_연습문제 2
#include <stdio.h>
int main(void)
{
int num;
printf("enter a number : ");
scanf("%d", &num);
if(num%2==0) printf("짝수");
if(num%2==1) printf("홀수");
return 0;
}