Home / Programs / Write a C program to accept all character(A to Z) and check it is even or odd place using the ternary operator (A is an odd place and B is in the even place)
Programming Example

Write a C program to accept all character(A to Z) and check it is even or odd place using the ternary operator (A is an odd place and B is in the even place)

👁 1,305 Views
💻 Practical Program
📘 Step by Step Learning
Write a C program to accept a character and check it is even or odd using the ternary operator

Program Code

#include<stdio.h>
void main()
{ 
int i;
for(i=65; i<91; i++)
	{
	(i%2 == 0) ? printf("\n[%c] => This is Even",i) : printf("\n[%c] => This is Odd",i) ;
	}
}

Output

[A] => This is Odd
[B] => This is Even
[C] => This is Odd
[D] => This is Even
[E] => This is Odd
[F] => This is Even
[G] => This is Odd
[H] => This is Even
[I] => This is Odd
[J] => This is Even
[K] => This is Odd
[L] => This is Even
[M] => This is Odd
[N] => This is Even
[O] => This is Odd
[P] => This is Even
[Q] => This is Odd
[R] => This is Even
[S] => This is Odd
[T] => This is Even
[U] => This is Odd
[V] => This is Even
[W] => This is Odd
[X] => This is Even
[Y] => This is Odd
[Z] => This is EvenPress any key to continue . . .

Explanation

Nope

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.