PLAY WITH CODING

Home Basic Program If & Else Loops Conversion Pattern logo

Program Based on If & Else

Program to check whether a number is even or odd

Input - Output

Input
Enter a number : 6

Output
6 is an even number

Input
Enter a number : 13

Output
13 is an odd number

Algorithm

Step 1: START

Step 2: Take a number 'num' as an input.

Step 3: Check the condition:

   if(num%2==0)

      print even number

   else

      print odd number

Step 4: END

CODE


/* check the number is even or odd */
#include  <stdio.h>
int main()
{
      int num;
      printf(" Enter a number : ");
      scanf("%d",&num);
      if(num%2==0)
          printf(" %d is an even number",num);
      else
          printf(" %d is an odd number",num);
    return 0;
}


/* check number is even or odd */
#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<" Enter a number : ";
      cin>>num;
      if(num%2==0)
          cout<<num<<" is an even number";
      else
          cout<<num<<" is an odd number";
    return 0;
}

OutPut

Enter a number : 6

6 is an even number