#include<stdio.h>
#include<conio.h>
int main()
{
int x,z;
printf("Enter Number:");
scanf("%d",&x);
z=(x==1 || x==100 ? 1 : 0);
printf("z=%d",z);
getch();
}
The program takes an input integer value “x”. Then it checks the value of x using a logical OR operator. The expression x==1 || x==100
returns true if the value of x is equal to either 1 or 100, otherwise, it returns false. The ternary operator (?
) assigns the value 1 to the variable “z” if the expression x==1 || x==100
returns true, otherwise, it assigns 0 to the variable “z”.
Finally, the value of “z” is printed on the screen. If the entered value of “x” is equal to 1 or 100, the output will be 1, otherwise, it will be 0. The getch()
function is used to pause the screen until a user presses any key.
Thanks
Write a program to display 1 if inputted number is either 1 or 100 otherwise 0.use the logical OR operator.