-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path01_is_even.c
42 lines (35 loc) · 996 Bytes
/
01_is_even.c
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// // C program to check whether a given number is an even number or an odd
// // Header Files
#include <stdio.h>
#include <conio.h>
// // Main Function Start
int main()
{
int num;
printf("\nEnter a number to check whether it is Even or Odd => ");
scanf("%d", &num);
// // 1st Approach (using % Modulus opertor)
if (num % 2)
printf("\n%d is Odd", num);
else
printf("\n%d is Even", num);
// // 2nd Approach (using & Bitwise AND operator)
// // if (num & 1)
// // printf("\n%d is Odd", num);
// // else
// // printf("\n%d is Even", num);
// // 3rd Approach
// // if (num / 2.0 - num / 2 == 0)
// // printf("\n%d is Even", num);
// // else
// // printf("\n%d is Odd", num);
// // 4th Approach
// // if (num / 2 * 2 == num)
// // printf("\n%d is Even", num);
// // else
// // printf("\n%d is Odd", num);
printf("\n");
getch();
return 0;
}
// // Main Function End