forked from 2015jamrajput/Medium_C_codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop.c
More file actions
68 lines (66 loc) · 1.6 KB
/
loop.c
File metadata and controls
68 lines (66 loc) · 1.6 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
#include<stdio.h>
int main(){
/* int i=0, n;
printf("enter the value of n \n");
scanf("%d", &n);
for(i=0; i<n; i++){
printf("%d\n", i+1);
}*/// from here another question
// int i=5;
// for(i=5; i; i--)
// printf("%d\n", i); from here n natural number in reverse order
/* int i;
int n;
printf("enter the value of n \n");
scanf("%d", &n);
for(i=n; i; i--)
printf("%d\n", i);*/
//table of any natural number n
/*int n, i=0;
printf("enter the value of n whose table u want\n");
scanf("%d", &n);
for(i=0; i<=10; i++){
printf("%d\n", n*i);
}*/
//multiplication of 10 in reverse order
/*int i=0;
for(i=0; i<=10; i++){
printf("%d\n",100-(10*i) );
}*/
//another method for above question
/*int i=10;
for(i=10;i;i--){
printf("%d\n", 10*i);
}*/
// print sum of n natural no. using loop
/*int sum=0, i=0, n;
printf("enter the value of n\n");
scanf("%d", &n);
for(i=0; i<=n; i++){
sum= sum + i; // this line can also be written as sum +=i
printf("%d\n", sum);
}*/
//same above question with while loop
/*int i=0, n, sum=0;
printf("enter the value of n\n");
scanf("%d",&n);
while(i<=n){
sum = sum+i;
i++;
}
printf("%d\n", sum);*/
//sum of the numbers occuring in the multiplication table of 8
/*int i=0, sum=0;
for(i=0; i<=10; i++){
8*i;
sum= sum + 8*i;}
printf("%d\n", sum); */
// factorial of a number
int i=1, factorial=1, n;
scanf("%d", &n);
for(i=1; i<=n; i++){
factorial=factorial*i;
}
printf("%d", factorial);
return 0;
}