Determine if a number is even or odd. - C Statement

C examples for Statement:if

Description

Determine if a number is even or odd.

Demo Code

#include <stdio.h>

int main (void)
{
    int number_to_test, remainder;

    printf ("Enter your number to be tested: ");
    scanf ("%i", &number_to_test);

    remainder = number_to_test % 2;/*  w ww.  ja v  a2 s  . c o m*/

    if (remainder == 0)
        printf ("The number is even.\n");

    if (remainder != 0)
        printf ("The number is odd.\n");

    return 0;
}

Result


Related Tutorials