C program check whether a number is even or odd
Write a C program to check whether a number is even or odd.
Example:
Enter no: 2
Output: No is even
Enter no: 9
Output: No is odd
Enjoy it.............
Enjoy it.............
Enter no: 2
Output: No is even
Enter no: 9
Output: No is odd
Required knowledge:
Fundamentals of C, Data types, Taking user input in C, IF-else
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*****************************************************
* C program to check a number is positive or not *
*****************************************************/
#include <stdio.h>
void main()
{
int num;
/* Reads number from user */
printf("Enter any number to check even or odd: ");
scanf("%d", &num);
/* Check if the number is divisible by 2 then it is even */
if(num%2 == 0)
{
// num % 2 is 0
printf("Number is Even.\n");
}
else
{
//num % 2 is 1
printf("Number is Odd.\n");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| /***************************************************** * C program to check a number is positive or not * *****************************************************/#include <stdio.h>
void
main(){ int num; /* Reads number from user */ printf("Enter any number to check even or odd: "); scanf("%d", &num); /* Check if the number is divisible by 2 then it is even */ if(num%2 == 0) { // num % 2 is 0 printf("Number is Even.\n"); } else { //num % 2 is 1 printf("Number is Odd.\n"); }} |
Enjoy it.............
Enjoy it.............

Comments
Post a Comment
Dears! Yours Comment approved in 24 hours also your answer in 24 hours.......