Computer >> 컴퓨터 >  >> 프로그램 작성 >> C 프로그래밍

'else if 사다리' 조건문을 C 언어로 사용하는 방법은 무엇입니까?

<시간/>

기타 − 사다리가 다중 결정을 작성하는 가장 일반적인 방법인 경우

래더가 다음과 같은 경우 else 구문 -

if (condition1)
   stmt1;
else if (condition2)
   stmt2;
   - - - - -
   - - - - -
   else if (condition n)
      stmtn;
   else
      stmt x;

순서도

아래의 순서도를 참조하십시오 -

 else if 사다리  조건문을 C 언어로 사용하는 방법은 무엇입니까?

예시

다음은 Else If Ladder 조건문을 실행하는 C 프로그램입니다 -

#include<stdio.h>
void main (){
   int a,b,c,d;
   printf("Enter the values of a,b,c,d: ");
   scanf("%d%d%d%d",&a,&b,&c,&d);
   if(a>b){
      printf("%d is the largest",a);
   }
   else if(b>c){
      printf("%d is the largest",b);
   }
   else if(c>d){
      printf("%d is the largest",c);
   }
   else{
      printf("%d is the largest",d);
   }
}

출력

위의 프로그램을 실행하면 다음과 같은 결과가 나온다 -

Enter the values of a,b,c,d: 2 3 4 5
5 is the largest