forked from CPRO-Session1/Assignment4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsumarray.c
More file actions
49 lines (36 loc) · 1.08 KB
/
sumarray.c
File metadata and controls
49 lines (36 loc) · 1.08 KB
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
48
49
/*Yael Kelmer.
This code takes a user inputed array and outputs an array of the sum of all the integers in the array execpt for the indexed integer*/
#include <stdio.h>
int main ()
{
printf ("Please insert the length of the array (how many integers you want in your list of integers)\n");
int lengthArray;
scanf ("%d", &lengthArray);
printf ("Please insert the integers you want to be in the array (remember it has to match the length of the array) \n");
int userArray [lengthArray];
int i;
int userInput;
for (i = 0; i < lengthArray; i++) {
scanf ("%d", &userInput);
userArray [i] = userInput;
}
int outputArray [lengthArray];
int j;
int sum = 0;
for (j = 0; j < lengthArray; j++) {
sum = sum + userArray [j];
}
for (i = 0; i < lengthArray; i++) {
outputArray [i] = sum - userArray [i];
}
printf ("This is your input array: [ ");
for (i = 0; i < lengthArray; i++) {
printf ("%d ", userArray [i]);
}
printf ("]\n");
printf ("This is your ouput array: [ ");
for (i = 0; i < lengthArray; i++) {
printf ("%d ", outputArray [i]);
}
printf ("]\n");
}