Determine the value of b using the conditional statement.

c
#include<stdio.h>
#include<conio.h>
int main()
{
	int a,b;
	printf("Enter any integer whose value is 5 or any other:-");
	scanf("%d",&a);
	b=(a==5 ? 3 : 4);
	printf("Calculated valu of b is:- %d\n",b);
	getch();
}

This program is designed to determine the value of b based on the inputted value of a. It starts by asking the user to input any integer either 5 or any other. Then, the value of a is stored in the integer variable a using the scanf function.

Next, the conditional operator (?:) is used to evaluate the condition a==5 and assign the value of b based on its outcome. If a is equal to 5, then b is assigned the value 3, otherwise, b is assigned the value 4.

Finally, the calculated value of b is printed to the screen using the printf function. The program terminates after the user presses any key.

Thanks

Determine the value of b using the conditional statement.

Leave a Reply

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

Scroll to top