nested if statement 란 중첩 if 문을 의미한다.
즉, 다른 if 문 내에 하나 이상의 if 문이 포함된 구조이다.
#include <stdio.h>
int main()
{
int age = 25;
int salary = 60000;
if (age > 18) {
printf("You are an adult.\n");
if (salary > 40000) {
printf("You have a decent income.\n");
} else {
printf("You might want to consider a higher paying job.\n");
}
} else {
printf("You are a minor.\n");
}
return 0;
}
자 , 한줄 씩 알아보자
우선
age 변수는 25,
salary = 60000 이다.
age> 18 이라면 You are an adult 를 출력하고,
그에 이어 salary > 40000 이라면 You have a decent income 을 출력한다
if 문 내에서 else, 즉 salary <= 40000 이라면 You might want to consider a higher paying job 을 출력한다.
그러나 age <=18 이라면, You are a minor 를 출력하며 프로그램을 마친다.
'C language' 카테고리의 다른 글
| [c언어]1에서 100까지의 홀수 중 소수를 출력해보자. (0) | 2023.12.18 |
|---|---|
| [C언어] if문에 대해 배워보자 (0) | 2023.12.10 |
| [Udemy] Print the byte size of the basic data types 챌린지 (0) | 2023.12.08 |
| [C]사각형 길이를 정의하고 둘레와 넓이를 구해보자 (0) | 2023.11.30 |