Write a program to display 1 if the inputted no. is except 100 otherwise 0.Use the logical NOT (!)

#include<stdio.h>
#include<conio.h>
int main()
{
	int x,z;
	printf("Enter number : ");
	scanf("%d", &x);
	z=(x!=100 ? 1 : 0);
	printf("d :",z);
	getch();
}

/*In the above program !NOT operator is used with the conditional operator.The value of x is also 
entered.Here,is the value of x is other than 100,then 1 assigned to z otherwise 0.*/

In this program, the user is prompted to enter a number using the scanf() function. The value of x is then evaluated using the logical NOT (!) operator in conjunction with the conditional operator (?). If x is not equal to 100, the expression x!=100 returns true, and the value 1 is assigned to the variable z. If x is equal to 100, the expression x!=100 returns false, and the value 0 is assigned to z. Finally, the value of z is displayed to the user using the printf() function. The program terminates with the use of the getch() function which waits for a user to press a key on the keyboard.

Thanks

Write a program to display 1 if the inputted no. is except 100 otherwise 0.Use the logical NOT (!)

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top