Write a program in C for showing working of different
logical operator in C.
Your program should guide users with proper message/menu on
the console.
Answer Posted / gajendra patil
# include <stdio.h>
int main(){
int ch,n1,n2;
t: printf("\nUSE OF LOGICAL OPERATORS");
printf("\n--------------------------");
printf("\n\tMENU");
printf("\n--------------------------");
printf("\n1. OR(||)\n2. AND(&&)\n0. EXIT");
printf("\n--------------------------");
printf("\nEnter your Choice: ");
scanf("%d",&ch);
switch(ch){
case 1:
printf("\nUSE OF OR\ne.g. [ if A>0 or B>0 ]");
printf("\n======================");
printf("\nEnter value for A: ");
scanf("%d",&n1);
printf("\nEnter value for B: ");
scanf("%d",&n2);
if(n1>0 || n2>0){
printf("\nAt least one/both has value(s)\n");
}else
printf("\nBoth are empty\n");
break;
case 2:
printf("\nUSE OF AND\ne.g [ if A>0 and B>0 ]");
printf("\n======================");
printf("\nEnter value for A: ");
scanf("%d",&n1);
printf("\nEnter value for B: ");
scanf("%d",&n2);
if(n1>0 && n2>0){
printf("\nBoth has values\n");
}else
printf("\nNo value(s) for any one/both\n");
break;
default:
printf("\nInvalid choice! try again");
printf("\n===========================");
goto t;
}
return 0;
}
Is This Answer Correct ? | 16 Yes | 5 No |
Post New Answer View All Answers
Should I learn data structures in c or python?
can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......
Why shouldn’t I start variable names with underscores?
What are variables and it what way is it different from constants?
What is selection sort in c?
Why is struct padding needed?
Hello. How to write a C program to check and display president party like if i type in the console "biden" and hit enter the output shoud be : "biden is democrat" and if i type "trump" and hit enter the output shoud be: "trump is republican"
Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)
What are the features of c languages?
What is substring in c?
What is a memory leak? How to avoid it?
find out largest elemant of diagonalmatrix
What is floating point constants?
Explain how do you generate random numbers in c?
What is the difference between array_name and &array_name?