-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor.c
More file actions
42 lines (33 loc) · 730 Bytes
/
Copy pathfor.c
File metadata and controls
42 lines (33 loc) · 730 Bytes
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
// FOR LOOP IN C PROGRAMMING
# include<stdio.h>
int main(){
/* Syntax of the for loop
for( initialization expression;test expression;update expression){
code inside the for loop
}
*/
// a program to add numbers from 0 to 100
/*int total=0;
for (int num=1; num<=100;num++){
total= total+num;
//printf("Sum=%d\n",total);
}
printf("Sum=%d\n",total);
*/
// the sum of even numbers
/*int total=0;
for (int num=0; num<=100;num=num+2){
total= total+num;
//printf("Sum=%d\n",total);
}
printf("Sum=%d\n",total);
*/
// the sum of odd numbers
int total=0;
for (int num=1; num<=100;num=num+2){
total= total+num;
//printf("Sum=%d\n",total);
}
printf("Sum=%d\n",total);
return 0;
}