-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp3a.c
39 lines (32 loc) · 753 Bytes
/
p3a.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
#include <stdio.h>
int main()
{
int num_1 = 0;
int count = 1;
int sum = 0;
printf("Enter a number: ");
scanf("%d", &num_1);
//while loop
printf("While loop \n");
while(count <= num_1)
{
printf("%d ", count);
sum = sum + count;
count = count + 3;
}
printf("\n============================= \n");
printf("the sum of these number is %d", sum);
printf("\n============================= \n");
sum = 0;
//for loop
printf("\nFor loop \n");
for (count = 1 ; count <= num_1; count = count + 3)
{
printf("%d ", count);
sum = sum + count;
}
printf("\n============================= \n");
printf("the sum of these number is %d", sum);
printf("\n============================= \n");
return 0;
}