Tuesday, May 15, 2012

Test Programming with C Problem 8

/* Problem 8: Any integer is input through keyboard. Write a program to find out whether it is an odd number or even number. */

#include<stdio.h>
#include<conio.h>

int check_oe(int x);

int main()
{
    int num, check;
   
    printf("Please input a number:\n");
    scanf("%d", &num);
   
    check = check_oe(num);
   
    if(check == 0) printf("%d is an even number.\n", num);
    else printf("%d is an odd number.\n", num);
   
   
    getch();
    return 0;  
}

int check_oe(int x)
{
    int test;
    test = x % 2;
    return test;
   
}

No comments:

Post a Comment

No Spamming Please.