C program to check odd or even

Google 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

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on hitesh.xc@gmail.com or 8076671483

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

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders.

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar.

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user.

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects.

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483