Tuesday 8 March, 2011

print 2,4,6,8,...,n

Print series 2, 4, 6, 8,…....,n.
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n; // declare two integer type variables
clrscr(); // clears the output window
printf("\n Enter the number : ");
scanf("%d",&n); // input the value of n
printf(“\n”); // will break the line on output window
for(i=2;i<=n;i++)
{
if(i%2==0)
{
printf(" %d ",i);
}
}
getch();
return 0;
}
Output:
Enter the number : 14
2 4 6 8 10 12 14

No comments:

Post a Comment