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
What is class and object in c?
Why do we need volatile in c?
What does the function toupper() do?
What is a constant?
What is null pointer constant?
How can I send mail from within a c program?
How to set file pointer to beginning c?
What is malloc and calloc?
which is an algorithm for sorting in a growing Lexicographic order
In C, What is the #line used for?
Explain that why C is procedural?
Is c# a good language?
Can a function argument have default value?
Define C in your own Language.
what is event driven software and what is procedural driven software?