C program to identify a number as even or odd - wordsclank.in

Saturday 8 April 2017

C program to identify a number as even or odd

An even number is an integer which is "evenly divisible" by two. This means that if the integer is divided by 2, it yields no remainder.
For example, 2,22,68.etc.
An odd number is an integer which is not a multiple of two. If it is divided by two the result is a fraction.
For example, 3,23,69,etc.


odd number, even number, odd even in c

PROBLEM STATEMENT

Write a program in C to identify a number as even or odd





SOURCE CODE:

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
#include
 
void main()


         {

          int num, rem;

          printf("Enter number:");

          scanf("%d",&num);

          rem = num % 2;

          if(rem = = 0)

            {

                  printf("%d is even",num);

             }

           else

             {

                  printf("%d is odd",num);

              }

            }

OUTPUT

even number,odd number,odd even in c

Explanation

First within the main() function we declared two integer variable num and rem.Then we display a message for the user to take input and we store it in n.Next divide the num by 2 and store it into rem.Then we are using a if-else loop to check whether the rem is equals to zero or not.If rem is equals to zero then it is a even number and we will display it as a even number, else we will print it as odd number.

Related Topics



No comments:

Post a Comment