write a program to check whether the
number is even or odd
Answers
Answered by
0
Program to Check Odd or Even Using the Ternary Operator
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
(num % 2 == 0) ? printf("%d is even.", num) : printf("%d is odd.", num);
return 0;
}
Output
Enter an integer: 33
33 is odd.
Answered by
1
- C0DE is written in C Language.
- Here, we have used if-else statement to find out whether the no. is odd or even.
C0DE
#include <stdio.h>
int main()
{
int a, b;
printf("Enter a number: ");
scanf("%d", &a);
if(a%2==0){
printf("%d is even \n", a);
}
else{
printf("%d is odd", a);
}
return 0;
}
EXAMPLE OUTPUT
Enter a number: 5
5 is odd.
Attachments:
Similar questions