-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor_loop_practice_set.c
More file actions
190 lines (142 loc) · 3.12 KB
/
for_loop_practice_set.c
File metadata and controls
190 lines (142 loc) · 3.12 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// ==================================================
// ======================= 👉👉 🔹🔹 Practice-Problem =========
// ==================================================
// Question - 1. Print the table of a number input by the user
#include <stdio.h>
int main (){
int n;
int t = n;
printf("Entr Number :");
scanf("%d",&n);
int i = 1;
for(int i = 1 ; i<=n ; i++){
t = n*i;
printf("%d\n",t);
}
return 0;
}
#include <stdio.h>
int main (){
int n;
// int t = n;
printf("Entr Number :");
scanf("%d",&n);
int i = 1;
for(int i = 1 ; i<=n ; i++){
i = n*2;
printf("%d\n",i);
}
return 0;
}
#include <stdio.h>
int main (){
int n;
printf("Enter Number :");
scanf("%d", &n);
for(int i = 1 ; i<=10; i++ ){
printf("%d\n",n*i);
}
return 0 ;
}
// Question - 1.Keep taking numbers as input from user until user enters an odd number
#include <stdio.h>
int main () {
int n;
do{
printf("Enter Number : ");
scanf("%d" , &n);
printf("%d\n" , n);
if( n % 2 != 0 ){
break ;
}
}while(1);
printf("Bey !\n");
return 0 ;
}
// Question - 2.Keep taking numbers as input from user until
// user enters a numbers which is multiple of 7
#include <stdio.h>
int main(){
int n;
do{
printf("Enter Number :");
scanf("%d",&n);
printf("%d\n" , n);
if(n % 7 == 0){ // multiple of 7
break;
}
}while(1);
printf("Sad song\n " );
return 0 ;
}
// continue
#include <stdio.h>
int main () {
for(int i = 1 ; i<=6;i++){
if(i == 5){ // Skip
continue;
}
printf("%d\n",i);
}
return 0 ;
}
// Question - 3.Print all numbers froms 1 to 10 except for 6
#include <stdio.h>
int main () {
for(int i = 5 ; i<=50 ; i++){
if(i == 6){ // Skip
continue;
}
printf("%d\n",i);
}
return 0 ;
}
// Question - 3 Print all the odd numbers 5 to 50
#include <stdio.h>
int main(){
for(int i = 5 ; i <=50; i++){
if(i % 2 !=0){
printf("%d\n",i);
}
}
return 0 ;
}
// Question - 3 Print the fctorial of a number n
#include <stdio.h>
int main(){
int n;
printf("Emter Number : ");
scanf("%d" , &n);
int fac = 1;
for(int i = 1 ; i<=n; i++ ){
fac= fac*i;
}
printf("Final Output %d\n",fac);
return 0 ;
}
// Question - 4.. Print reverse of the table for a number
#include <stdio.h>
int main(){
int n;
printf("Enter Number : ");
scanf("%d", &n);
for(int i = 10; i>=1; i--){
// n = i*n;
printf("%d\n", i*n);
}
return 0 ;
}
// Question - 5.. Calculate the sum of all numbers between 5 & 50 (including 5 & 50)
#include <stdio.h>
int main(){
int sum = 0;
for(int i = 5 ; i<=50 ; i++ ){
sum = i+sum ; // sum +=i ;
}
printf("sum is %d\n", sum);
return 0 ;
}
// #include <stdio.h>
// int main(){
// return 0 ;
// }