-
Notifications
You must be signed in to change notification settings - Fork 0
/
Natural_Numbers.C
87 lines (59 loc) · 1.34 KB
/
Natural_Numbers.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* C program to print all natural numbers from 1 to n
*/
//1.with while loop
#include <stdio.h>
void main()
{
int n, i, s=0;
printf("Enter The Limit: ");
scanf("%d", &n);
while(i!=n)
{
i = i+1;
printf("%d\t", i);
s = s+1;
}
}
//2.with for loop
#include <stdio.h>
int main()
{
int i, n;
/* Input upper limit from user */
printf("Enter any number: ");
scanf("%d", &n);
printf("Natural numbers from 1 to %d : \n", 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 each repetition print the value of i.
*/
for(i=1; i<=n; i++)
{
printf("%d\n", i);
}
return 0;
}
//3.print natural series in range
#include <stdio.h>
int main()
{
int i, start, end;
/* Input start and end limit */
printf("Enter start value: ");
scanf("%d", &start);
printf("Enter end value: ");
scanf("%d", &end);
printf("Natural numbers from %d to %d : \n", start, end);
/*
* Start loop counter from start (i=start) and go till
* end (i<=end), increment the loop count by 1 to get
* the next value. For each repetition print the value of i.
*/
for(i=start; i<=end; i++)
{
printf("%d\n", i);
}
return 0;
}