Use of Logical Operators

C allows usage of three logical operators, namely, &&, || and !. These are to be read as ‘AND’ ‘OR’ and ‘NOT’ respectively.
There are several things to note about these logical operators. Most obviously, two of them are composed of double symbols: || and &&. Don’t use the single symbol | and &.
The first two operators, && and ||, allow two or more conditions to be combined in an if statement. Let us see how they are used in a program. Consider the following example.

#include <stdio.h>
int main()
	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)
			printf("Second division");
			if (per >= 40)
				printf("Third division");
	return 0;

You may also like...

No © Loop and Break