-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLearningTask1.5_1_Españo_KylaCaryl(For Loop).c
36 lines (32 loc) · 1.65 KB
/
LearningTask1.5_1_Españo_KylaCaryl(For Loop).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
//CCIT 102 - Computer Programming 1//
//I have only used for loop in this program because I have encountered difficulties in inserting the while loop and do while.//
#include <stdio.h> //Preprocessor directive in C.//
int main() //Indicates the start of the program execution.//
{ //Begining of the function.//
int num, endnum, sum1 = 0, sum2 = 0;//Declaration of variables.//
//Input//
printf("Input starting integer:");//To display the information.//
scanf("%d",&num);//Allowing to enter the integer and stores it in the variable num.//
printf("Input ending integer:");//To display the information.//
scanf("%d",&endnum);//Allowing to enter the integer and stores it in the variable endnum.//
//Process//
printf("\nEVEN NUMBERS ");
printf("\n");//new line//
for(num=2;num<=endnum;num=num+2) //For loop//
{
printf("%d\t", num); //Output; \t for spaces between the integers//
if(num%2 == 0)//If the number modulo division 2 is equal to zero//
sum1 = sum1 + num; //Expression; fromula to perform the operation of printing the sum//
}
printf("Sum: %d", sum1); //Output; the sum//
printf("\nODD NUMBERS ");
printf("\n");//new line//
for(num=1;num<=endnum;num=num+2) //For loop//
{
if(num%2 != 0) //If the number modulo division 2 is not equal to zero//
printf("%d\t", num); //Output; \t for spaces between the integers//
sum2 = sum2 + num; //Expression; fromula to perform the operation of printing the sum//
}
printf("Sum: %d", sum2); //Output; the sum//
return 0; //Terminates the C program//
} //End of the function//