0% found this document useful (0 votes)
3 views1 page

Conditional Operator

The conditional operator, also known as the ternary operator, is a decision-making structure that evaluates a condition and returns one of two values based on the result. It can replace simple if-else statements and follows the syntax (condition)?true-case statement:false-case statement;. An example program demonstrates its use to check if a number is divisible by 7.

Uploaded by

aslamsaira437
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Conditional Operator

The conditional operator, also known as the ternary operator, is a decision-making structure that evaluates a condition and returns one of two values based on the result. It can replace simple if-else statements and follows the syntax (condition)?true-case statement:false-case statement;. An example program demonstrates its use to check if a number is divisible by 7.

Uploaded by

aslamsaira437
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Conditional operator

Conditional operator is a simple dicision making structure.It evaluates a condition and returns one of two values based on the result
of the condition.It can be used in place of simple if-else structure.It is also called Ternary operator as it uses three operands.

Syntax

(condition)?true-case statement:false-case statement;

Example

N=(a>50)?1:0;

The above statement will assign the value 1 to the variable N if the condition a>50 is true. It will assign the value 0 to N if the
condition is false.

This statement can be written by using if-else statement as follows:

If(a>50)

N=1;

else

N=0;

Program

Input a number and check it is divisible by 7 or not.

#include<stdio.h>

#include<conio.h>

main()

int n;

printf (“Enter a number:”);

scanf(“%d”,&n);

(n%7==0)?printf(“divisible”):printf(“not divisible”);

getch();

You might also like