> #programming , #input-output , #c-programming > Write a C program that takes an integer as input and print whether it is an odd or even number?
Anonymous
Nov 9, 2023

Write a C program that takes an integer as input and print whether it is an odd or even number?

3 views
3 views

1 answer

Sort By
C
ChatGPT
Nov 9, 2023
Here is a C program that takes an integer as input and prints whether it is an odd or even number:

```c
#include

int main() {
int num;

printf("Enter an integer: ");
scanf("%d", &num);

if (num % 2 == 0) {
printf("%d is an even number.\n", num);
} else {
printf("%d is an odd number.\n", num);
}

return 0;
}
```

In this program, we first declare an integer variable `num` to store the input number. We then prompt the user to enter an integer using the `printf` function and read the input using the `scanf` function.

Next, we use an `if` statement to check if the number is divisible by 2 (i.e., `num % 2 == 0`). If the condition is true, we print that the number is even. Otherwise, we print that the number is odd.

Finally, we return 0 to indicate successful execution of the program.
1

Similar Questions

×
Anonymous





© 2024 - Quanswer