C program to check odd or even

Advertisements

Prev Tutorial Next Tutorial

C program to check odd or even

Even numbers are those which are divisible by 2, and which numbers are not divisible 2 is called odd numbers.

But in term of programming for find even number we check the remainder of number is zero or not when number divided by zero, If remainder is equal to zero that means number is divisible by 2. To find remainder of any number you need to use modulo (%) operator in C language, which return remainder as a result.

C program to check odd or even

#include<stdio.h>
#include<conio.h>

void main()
{
int no;
clrscr();
printf("Enter any number: ");
scanf("%d",&no);
if(no%2==0)
{
printf("Even num");
}
else
{
printf("Odd num");
}
getch();
}

Output

Enter any num: 5
Odd num

C program to check odd or even using ternary or conditional operator

Check give number is Even or Odd

#include<stdio.h>
#include<conio.h>

void main()
{
int no;
clrscr();
printf("Enter any num : ");
scanf("%d",&no);
(no%2==0) ? printf("Even number") : printf("Odd number");
getch();
}

Output

Enter any num : 6
Even number

C program to check odd or even using bitwise operator

C program to check odd or even

#include<stdio.h>
#include<conio.h>

void main()
{
  int num;
  clrscr();
  printf("Enter any num : ");
  scanf("%d",&num);
  if(num & 1)
  {
  printf("%d is odd",num);
  }
  else
  {
  printf("%d is even",num);
  }
  getch();
}

Output

Enter any num: 20
20 is even

Program to print even number upto 100

program to print even number upto 100

#include<stdio.h>
#include<conio.h>

void main()
{
int n=2;
clrscr();
while(n<=100)
{
printf("  %d",n);
n=n+2;
}
getch();
}

Output

2 4 6 8 10 12....100

Prev Tutorial Next Tutorial

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Google Advertisements


Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements