Wednesday, 30 September 2015

Identification of Even and Odd number

Share it Please
Aim:

To write a program to find whether the given  number is even or odd.

Algorithm:

1. Read the number N.

2. Find the remainder of N divided by 2 using the Modulus operator (N%2);

3. If the remainder is zero

 The number is Even number

Otherwise

 The number is Odd number

4. Print the result.

5. Stop.

Program:

/* To find whether the number is even or odd*/

#include<conio.h>

#include<stdio.h>

void main()

{

int n,r;

clrscr();

printf("Enter a number:");

scanf("%d",&n);

r=n%2;

if(r==0)

else

getch();

printf("\n\tThe given number %d is even",n);

printf("\n\tThe given number %d is odd",n);

}

Output 1:

Enter a number:8

        The given number 8 is even

Output 2:

Enter a number:-7

        The given number -7 is odd

No comments:

Post a Comment

Blogroll

About

Designed By IAMNGP | Moon