Take a input from user and find out the number is odd/even using ternary operator.
Code goes like this :
/* Finding out the odd/even number using ternary operator */
#include<stdio.h>
int main()
{
int num;
printf("Enter a number : ");
scanf("%d",&num);
num%2==0 ? printf("Even Number") : printf("Odd Number") ; // use of ternary operators i.e. expression 1 ? expression 2: expression 3 ;
return 0;
}
Output: Even
----------------
Output : Odd
---------------
I have used Dev CPP to compile this program.
If you are using Turbo C++
IDE, then use conio.h in link section after stdio.h
and use getch(); to
hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you.
Odd/Even Program using ternary operator in C Programming
3:14 PM
C Programming
,
Odd Even Program in C Language
,
Ternary operator
,
Ternary operator in C
Edit
0 comments:
Post a Comment