-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum_loop.c
More file actions
46 lines (31 loc) · 747 Bytes
/
sum_loop.c
File metadata and controls
46 lines (31 loc) · 747 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
43
44
45
46
#include <stdio.h>
int main(void)
{
printf("Please enter the number of integers that will be summed: ");
int num_ints = NULL;
scanf("%d", &num_ints);
int intArray[num_ints];
int sum = NULL;
int scanf_sum = NULL;
int i = NULL;
for (i = 0; i < num_ints; i++)
{
printf("Please enter integer %d: ", i + 1);
scanf_sum = scanf_sum + scanf("%d", &intArray[i]);
}
if (scanf_sum != num_ints)
{
printf("You did not enter %d integers!\n", num_ints);
return 1;
}
else
{
int j;
for (j = 0; j < num_ints; j++)
{
sum = sum + intArray[j];
}
}
printf("Total sum: %d\n", sum);
return 0;
}