Software & Finance





C Programming (Turbo C++ Compiler) Loops - Read Numbers and Check Odd or Even Number





I have given here the code to read set of integers and display whether odd or even number.


Source Code


#include <stdio.h>


int main()

{

    printf("Program to find ODD or Even Number\n");

    while(1)

    {

        int n = 0;

        printf("\nEnter a number(-1 for Exit): ");

        scanf("%d",&n);

 

        if( n == -1)

            break;

 

        if((n % 2) == 0)

        {

            printf("%d is a EVEN number.\n", n);

        }

        else

        {

            printf("%d is a ODD number.\n", n);

        }

    }

    return 0;

}

Output


Program to find ODD or Even Number

 

Enter a number(-1 for Exit): 1

1 is a ODD number.

 

Enter a number(-1 for Exit): 2

2 is a EVEN number.

 

Enter a number(-1 for Exit): 3

3 is a ODD number.

 

Enter a number(-1 for Exit): 4

4 is a EVEN number.

 

Enter a number(-1 for Exit): 5

5 is a ODD number.

 

Enter a number(-1 for Exit): 6

6 is a EVEN number.

 

Enter a number(-1 for Exit): 7

7 is a ODD number.

 

Enter a number(-1 for Exit): -1

 

Press any key to continue . . .