C program to print all even numbers from 1 to n - IProgramX

Q. Write a program to accept an integer n and display all even numbers upto n


Program

#include<stdio.h>
int main()
{
int n,j=1;
printf("enter nth value:");
scanf("%d",&n);
n++;
while(n!=j)
{
if(j%2==0)
{
printf("%d\t",j);
    }
j++;
}
}

Output:

enter nth value:12
2       4       6       8       10      12

Post a Comment

0 Comments