-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass3.c
More file actions
71 lines (64 loc) · 1.18 KB
/
class3.c
File metadata and controls
71 lines (64 loc) · 1.18 KB
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
//1.wap to print first 10 natural no using for loop
#include <stdio.h>
int main() {
int i;
for (i = 1; i <= 10; i++)
printf("%d ", i);
return 0;
}
//or using while loop
#include <stdio.h>
int main() {
int i = 0;
while (i < 10) {
printf("%d ", i);
i++;
}
return 0;
}
//using do-while loop
#include <stdio.h>
int main() {
int i = 0;
do {
printf("%d ", i);
++i;
} while (i < 10);
return 0;
}
//2.wap to print first 10 natural no in reverse order without using decrement operator
#include <stdio.h>
int main() {
int i;
for (i = 1; i <= 10; i++)
printf("\n %d ", 11 - i);
return 0;
}
// 3.wap to print first 10 natural no in reverse order
#include <stdio.h>
int main() {
int i;
for (i = 10; i > 0; i--)
printf("\n %d ", i);
return 0;
}
//4.wap to print first n odd natural no
#include <stdio.h>
int main() {
int i, n;
printf("enter a no ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
printf("\n %d ", 2 * i - 1);
return 0;
}
//5.wap to print first n even natural no
#include <stdio.h>
int main() {
int i, n;
printf("enter a no ");
scanf("%d", &n);
for (i = 1; 2 * i <= 2 * n; i++)
printf("\n%d", 2 * i);
return 0;
}