Write a c program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Write a c program

Write a program to check if a number is even or odd with the help of switch-case construct and without using any if-else construct.

15th Jul 2022, 2:38 PM
Sujay Patra
Sujay Patra - avatar
4 Answers
15th Jul 2022, 4:07 PM
Кавун 🍉
Кавун 🍉 - avatar
+ 2
You just need to use the result from <number> modulo-by 2 for the switch subject. Then you go check whether it was zero (even number), or one (odd number). Go ahead try it out!
15th Jul 2022, 2:48 PM
Ipang
0
Dont forget about "break;" in switch-case construct
15th Jul 2022, 4:09 PM
Кавун 🍉
Кавун 🍉 - avatar
0
Thank u
15th Jul 2022, 4:11 PM
Sujay Patra
Sujay Patra - avatar