-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lecture8 Loops1.c
72 lines (46 loc) · 1.21 KB
/
Lecture8 Loops1.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
#include <stdio.h>
#include <stdlib.h>
//Written by Bunyamin Yavuz in 2022
//Loops (for)
int main()
{
/*
<-----Syntax of for loop in C----->
for (initial value; condition; incrementation or decrementation )
{
statements;
}
*/
// N times write "Welcome to the game platform User%d"
// Loop variable which has a comman usage (i)
int i;
// for (initial value; condition; incrementation or decrementation )
for(i = 1; i <= 10; i++) // (i++) = (i +=1)
{
//statements;
printf("Welcome to the game platform User%d\n",i);
}
// Summation with for loop
int j,sum = 0;
int lastNum;
printf("Enter the last element : ");
scanf("%d",&lastNum);
for(j = 1;j <= lastNum; j++)
{
// sum = sum + i;
sum += j;
}
printf("The summation is = %d",sum);
// Factorial with for loop
int k;
long int factor = 1;
int factorial;
printf("Would you like to see factorial of which number : ");
scanf("%d",&factorial);
for(k = 1;k <= factorial; k++)
{
factor *= k;
}
printf("The factorial of %d is = %ld",factorial,factor);
return 0;
}