forked from CPRO-Session1/Assignment4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharraySums.c
More file actions
43 lines (40 loc) · 921 Bytes
/
arraySums.c
File metadata and controls
43 lines (40 loc) · 921 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
#include <stdio.h>
int main()
{
printf("How many integers are in the array?\n");
int n;
scanf("%d", &n);
int first[n];
printf("Time to populate the array.\n");
for (int i = 0; i < n; i++) //Populates first array
{
printf("Integer %d?\n", i);
scanf("%d", &first[i]);
}
int second[n];
for (int cIsGarbage = 0; cIsGarbage < n; cIsGarbage++) //Sets all values in second array to 0
{
second[cIsGarbage] = 0;
}
for (int j = 0; j < n; j++) //Populates the second array
{
for (int k = 0; k < n; k++)
{
if (k != j) //Checks so the value you're at in first[] isn't counted
{
second[j] += first[k];
}
}
}
printf("Here's the first array:\n");
for (int l = 0; l < n; l++) //prints first array values
{
printf("%d ", first[l]);
}
printf("\nHere's the second array:\n");
for (int m = 0; m < n; m++) //prints second array values
{
printf("%d ", second[m]);
}
return 0;
}