Tuesday, August 30, 2022

C Program to Demonstrate else-if statement

if-else-if in C

In else – if a programmer can make decision among multiple conditions. In C "if statements" are executed from the top down approach. As soon as one of the if is true, the statement associated with if is executed, and the rest of the C else – if is bypassed. If none of the conditions are true, then the final else statement will be executed.

Syntax: 


if (condition)

    statement;
else if (condition)
    statement;
else if (condition)
    statement;
else if (condition)
    statement;
.
.
else

    statement;
Youtube Video


Flow Chart



Sorce Code

 //WAP to enter any three number

//and find the largest

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int n1, n2, n3;

printf("Enter any three numbers \n");

scanf("%d%d%d",&n1,&n2,&n3);

if(n1>n2 && n1>n3)

printf("%d is larger than %d and %d",n1,n2,n3);

else if(n2>n1&&n2>n3)

printf("%d is larger than %d and %d",n2,n1,n3);

else

printf("%d is larger than %d and %d",n3,n1,n2);

printf("\nEnd of program");

getch();

}


No comments:

Post a Comment