Use of logical operators in conjunction with ‘if’ statement
Example:
Sample program, using logical operators in conjunction with ‘if’ statement
#include<stdio.h>
int main(void)
{
int m1,m2,m3,m4,m5,per;
printf(“Enter marks in five subjects”);
scanf(“%d%d%d%d%d”,&m1,&m2,&m3,&m4,&m5);
per=(m1+m2+m3+m4+m5)/5;
if(per>--60)
printf(“First Division”);
if((per>=50)&&(per<60))
printf(“Second Division);
if((per>=40)&&(per<50))
printf(“Third Division”);
if(per<40)
printf(“fail”);
return 0;
}
OUTPUT
Enter marks in five subjects
40 40 40 40 40
Third Division
Use of logical operators in conjunction with ‘else if’ clause
Example:
Sample C program, using logical operators in conjunction with ‘else if’ clause
#include<stdio.h>
int main(void)
{
int m1,m2,m3,m4,m5,per;
printf(“Enter marks in five subjects”);
scanf(%d%d%d%d%d”,&m1,&m2,&m3,&m4,&m5);
per=(m1+m2+m3+m4+m5)/5;
if(per>=60)
printf(“First Division”);
else if(per>=50)
printf(“Second Division”);
else if(per>=40)
printf(“Third Division”);
else
printf(“Fail”);
return 0;
}
OUTPUT
Enter marks in five subjects
40 40 40 40 40
Third Division