if(condition) { statements ---------- } else { statements ---------- } next statements
#include⁢stdio.h> main() { int a; printf("Enter a Number "); scanf("%d",&a); if( a%2==0 ) printf("Number is EVEN"); else printf("Number is Odd"); }
Enter a Number 26 Number is Even
#include⁢stdio.h> main() { int a,b,c; printf("Enter 3 Angles "); scanf("%d %d %d",&a,&b,&c); if( a+b+c == 180 ) printf("Triangle can be formed"); else printf("Triangle cannot be formed"); }
Enter 3 Angles 60 60 60 Tirangle Can be formed
#include⁢stdio.h> main() { int a; printf("Enter a Number "); scanf("%d",&a); if( a >= 10 && a <= 99 ) printf("It is a 2 digit number"); else printf("It is not a 2 digit number"); }
Enter a Number 26 It is a 2 digit Number
#include⁢stdio.h> main() { int a; int x,y,z,w,s; printf("Enter a Number "); scanf("%d",&a); if(a>=1000 && a<=9999) { printf("It is a 4 digit number"); w=a % 10; x=a / 10 % 10; y=a / 100 % 10; z=a / 1000; s=w + x + y + z; printf("sum of digits is %d",s); } else printf("It is not a 4 digit number"); }
Enter a Number 2656 It is a 4-digit number sum of number is 19
#include⁢stdio.h> main() { int a,b,c,d,e; printf("Enter Marks for 5 subjects "); scanf("%d %d %d %d %d",&a,&b,&c,&d,&e); if(a>=40 && b>=40 && c>=40 && d>=40 && e>=40 ) printf("Student is Passed"); else printf("Student is Failed"); }
Enter marks of 5 subject 65 85 62 72 39 Student is Passed