Showing posts with label even. Show all posts
Showing posts with label even. Show all posts

Wednesday, May 16, 2018

C program to check whether the given number is odd or even.


Program code
#include <stdio.h>
#include <conio.h>
void main()
{
int a;
clrscr();
printf("Please input a number to find whether it is odd or even.\n");
scanf("%d",&a);
if ((a%2)==0)
printf("%d is even.\n",a);
else
printf("%d is odd.\n",a);
getch();
}

Example of output
Please input a number to find whether it is odd or even.
700
700 is even.

C program to display all even numbers between one and ten.


Program code
#include <stdio.h>
#include <conio.h>
void main()
{
int i;
clrscr();
printf(“The even numbers between one and 10\n”);
for (i=2;i<=10;i=i+2)
printf(“%d\n”,i);
getch();
}

Output
The even numbers between one and 10
2
4
6
8
10

C program to display all even numbers from one to the given number.


Program code
#include <stdio.h>
#include <conio.h>
void main()
{
int n=0, i;
clrscr();
printf(“If you input an integer, we will display all even numbers from one to that number.\n”);
scanf(“%d”,&n);
printf(“All even numbers from one to %d are given below.\n”,n);
for (i=1;i<=n;i++)
if ((i%2)==0)
printf(“%d\n”,i);
getch();
}

Example of output
If you input an integer, we will display all even numbers from one to that number.
22
All even numbers from one to 22 are given below.
2
4
6
8
10
12
14
16
18
20
22