else if statement
Title
Question
in the below coding,
if(c>=20)
printf("c is grater than or equal to 20");
else if(c<=20 && c>=10)
printf("c is between 10 and 20");
the value of c is 20,output will be "c is grater than or equal to 20",why the else if (qualifies for the same condition) does not get executed
C-and-Cpp If-And-Else-If-statement 00-01 min 10-20 sec
Answers:
Once the if(Condition1) block is executed, the remaining all else if condition will not be checked by any compiler.......
so it will not consider further
#include<studio.h> int main() { int a,b,c; printf("enter value of a:"); scanf("%d",&a); printf("enter value of b:" ); scanf("%d",&b); printf ("enter value of c:"); scanf("%d",&c); if(a>b&&a>c) { printf("a is the greatest \n"); } else if(b>a&&b>c) { printf("b is the greatest \n"); } else if(c>a&&c>b) { printf("c is the greatest \n"); } else { printf("Two or more values are equal \n"); } return 0; } OUTPUT:- enter value of a:15 enter value of b:7 enter value of c:20 c is the greatest

Login to add comment