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

Wednesday, May 16, 2018

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