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


Please Help Members By Posting Answers For Below Questions

Should I learn data structures in c or python?

567


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......

1396


Why shouldn’t I start variable names with underscores?

613


What are variables and it what way is it different from constants?

769


What is selection sort in c?

596






Why is struct padding needed?

619


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"

1572


Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)

798


What are the features of c languages?

613


What is substring in c?

626


What is a memory leak? How to avoid it?

557


find out largest elemant of diagonalmatrix

1636


What is floating point constants?

676


Explain how do you generate random numbers in c?

608


What is the difference between array_name and &array_name?

768