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
33 lines (25 loc) · 809 Bytes
/
sum.c
File metadata and controls
33 lines (25 loc) · 809 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
/*Mariposa Lee, returning a user-input array with cumulative sums of its elements*/
#include <stdio.h>
#include <math.h>
int main () {
char s[50];
int n, i, sum, length, bruh;
printf("Enter a number for your array length.\n");
scanf("%d", &length);
int str[length];
for (n=0; n!=length; n++) { /*if user inputs 5 for length, code will ask for 5 numbers*/
printf("Enter a number to put into your array.\n");
scanf("%d", &str[n]);
}
bruh=0;
sum=str[bruh];
printf("Here is your input array:\n");
for (n=0; n!=length; n++){ /*prints the numbers acquired from the first for loop*/
printf("%d\n", str[n]);}
printf("Here is the output array:\n");
for (i=0; i!=(length); i++){
printf("%d\n", sum);
sum+=str[bruh+=1]; /*bruh increases and adds to sum, resulting in cumulative sum*/
}
return 0;
}