Write a C program to enter two numbers and check if anyone of the numbers is even and display a message accordingly. ( Eg: one of the number is even or both numbers are not even)
Answers
Answered by
0
Answer:
#include <stdio.h>
int main()
{
int number1, number2;
printf("Enter first number: ");
scanf("%d", &number1);
printf("Enter first number: ");
scanf("%d", &number2);
if(number1 % 2 == 0 && number2 % 2 == 0) {
printf("Both %d and %d are even numbers", number1, number2);
}else if(number1 % 2 == 0) {
printf("%d is an even number", number1);
}else if(number2 % 2 == 0) {
printf("%d is an even number", number2);
}
return 0;
}
Explanation:
- We are accepting 2 numbers from the user.
- Then we are checking if both the number are even or not.
- Then we are checking if number 1 is even or not, then we are printing it.
- Lastly, we are checking if number 1 is even, then we are printing it
Similar questions