C Program to print first n natural numbers using while loop
Program
#include<stdio.h>
void main()
{
int i, n;
printf("Enter the value of n\t");
scanf("%d", &n);
printf("Printing natural numbers from 1 to %d\n", n);
i = 1;
while(i <= n)
{
printf("%d\t", i);
i++;
}
printf("\n");
}
Output
Enter the value of n 5
Printing natural numbers from 1 to 5
1 2 3 4 5