Skip to content

Commit ca10dbb

Browse files
authored
print n natural numbers
Program to print natural numbers from 1 to n.
1 parent c5c05c2 commit ca10dbb

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Diff for: print n natural numbers

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* C program to print all natural numbers from 1 to n
3+
*/
4+
5+
#include <stdio.h>
6+
7+
int main()
8+
{
9+
int i, n;
10+
11+
/* Input upper limit from user */
12+
printf("Enter any number: ");
13+
scanf("%d", &n);
14+
15+
printf("Natural numbers from 1 to %d : \n", n);
16+
17+
/*
18+
* Start loop counter from 1 (i=1) and go till n (i<=n)
19+
* increment the loop count by 1 to get the next value.
20+
* For each repetition print the value of i.
21+
*/
22+
for(i=1; i<=n; i++)
23+
{
24+
printf("%d\n", i);
25+
}
26+
27+
return 0;
28+
}

0 commit comments

Comments
 (0)