C Programming language

adplus-dvertising
C Program example: Using logical operators
Previous Home Next
Use of Logical Operator

In this program sex and ms are the variable of char type and age is the variable of integer type. and operator is denoted as && and or operator is denoted as ||

#include <stdio.h>
#include <conio.h>
main()
{
	char sex, ms;
	int age;
	clrscr();
	printf ("Enter Age, Sex, Merital Status");
	scanf ("%d %c %c" &age,&sex,&ms);
	if ((ms=='M')||(ms=='U'&&sex=='M'&&age>30)||(ms=='M')||
    (ms=='M'&&sex=='F'&&age>25))
		printf ("Driver is insured");
	else
		printf ("Driver is not insured");
}
Output :

Enter Age, Sex, Marital Status

35 F M

Driver is insured

Previous Home Next