Logical && and logical ||
logical && : If all are true then only true otherwise false.
logical || : if any one is true then it is true otherwise false.
Program on logical operators
A company insures its
drivers in the following cases:
− If the driver is
married.
− If the driver is
unmarried, male & above 30 years of age.
− If the driver is
unmarried, female & above 25 years of age.
In all other cases
the driver is not insured. If the marital status, sex and age of the driver are
the inputs, write a program to determine whether the driver is to be insured or
not.
#include<stdio.h>
int main()
{
int age;
char sex, married;
printf(“Is the driver married? y/n “);
scanf(“%c”, &married);
printf("Enter the AGE and SEX of the Driver
\n");
scanf("%d %c", &age, &sex);
if((married==‘y’’)||(married==‘n’ &&
age>30 && sex=='m')||(married==‘n’ || age>25 &&
sex=='f'))
printf("Insurance can be carried out \n");
else
printf("Insurance can not be carried out \n");
return 0;
}