Write a C Program by using Logical AND and OR Operator

Engg.... | 03:37 | | Best Blogger Tips
Logical Operators

Statement of C Program: This Program illustrates the logical ANDing and ORing operations:

#include<stdio.h>
#include<conio.h>
void main()
{
int a , b , c;
clrscr();
a = 4 , b = 3;

c = a && b;
b = a||b||c;
a = a && b||c;
printf("%d" , a\n);
printf("%d" , b\n);
printf("%d" , c\n);
}

Output:
1
1
1


Example:

Let   a=2    b=4    c=3
Solve the Logical Expression:     a && b||c && (!b)
Solution:
2 && 4||3 && (!4)
2 && 4||3 && (0)
1||3 && 0
1||0
1

Practise Questions:
What is the Output of the Following Programs:

1. 
main() 
{
int a = 10 , b = 12 , c = 15;
a = a && b || c;
b = a || b && c;
c = a && b && c;
printf("%d" , a\n);
printf("%d" , b\n);
printf("%d" , c\n);
}

2. 
 main() 
{
int x = 2 , y = 3 , s1 , s2 ;
s1 = x + (++y);
s2 = ++x + y++ ;
printf("%d\n%d\n" , s1 , s2);
}
                  
                                                          That's All
Please Share it! :)
Do you like this Story?

Get Free Email Updates Daily!

Follow us!

0 comments:

Post a Comment