Natural number
Natural numbers are numbers that are common and clearly in nature. As such, it is a whole, nonnegative number.
Logic
To print the first N natural number we only have to run one single loop from 1 to N.
After taking input (num) from user start one loop from 1 to num, and then inside the loop simply print the current variable “i”.
See also: Calculate sum of first N natural numbers
Program
#include <stdio.h> int main() { int i, num; // Take number from user printf("Enter any number : "); scanf("%d", &num); printf("\nNatural numbers from 1 to %d\n", num); for(i = 1; i <= num; i++) { printf("%d ", i); } return 0; }
Output
Enter any number : 10
Natural numbers from 1 to 10
1 2 3 4 5 6 7 8 9 10