This is a simple program to illustrate the coding flow.
Since all even numbers are divisible by 2
Algorithm:
READ input into number
IF MOD( number , 2 ) IS EQUAL TO ZERO THEN number IS even
IF MOD( number , 2 ) IS NOT EQUAL TO ZERO THEN number IS odd.
Code Listing:
- int main()
- {
- int n;
- printf ("Enter a number: ");
- scanf ("%d",&n);
- if (n%2 ==0 ) {
- printf ("The number is Even");
- } else {
- printf ("The number is Odd");
- }
- getch();
- return 0;
- }
No comments:
Post a Comment