C program to print all natural numbers from 1 to n using if
#include<stdio.h>
int main()
{
int n,i;
printf("Enter any Number: ");
scanf("%d",&n);
/* Start loop counter from 1 (i=1) and go till n (i<=n)
increment the loop count by 1 to get the next value */
for(i=1;i<=n;i++)
{
printf("%d\n",i);
}
return 0;
}
Output
Enter any Number: 7
1
2
3
4
5
6
7