forked from CPRF-Session2/Assignment4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum.c
More file actions
47 lines (39 loc) · 620 Bytes
/
sum.c
File metadata and controls
47 lines (39 loc) · 620 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
47
/* Drew French */
/* Given an array,
* creates an output
* array of the same
* size where out[3]
* = in[1] + in[2] +
* in[3]
*/
#include <stdio.h>
int in[50];
int n;
int i;
int j;
int out[50];
int main()
{
do
{
printf("How many values would you like to have in the array? (max 50): ");
scanf("%d", &n);
printf("\n");
} while(n > 50 || n < 2);
for(i = 0; i < n; i++)
{
printf("Enter value #%d: ", i + 1);
scanf("%d", &in[i]);
out[i] = 0;
for(j = i; j >= 0; j--)
{
out[i] += in[j];
}
}
printf("%d", out[0]);
for(i = 1; i < n; i++)
{
printf(", %d", out[i]);
}
return 0;
}