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
48 lines (47 loc) · 1.02 KB
/
sumarray.c
File metadata and controls
48 lines (47 loc) · 1.02 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
/*Lloyd Page*/
/* user inputed array where the index is equal to the sum of all other items in it except what's in the current index with repeatability*/
/*O(n^3)*/
#include<stdio.h>
int main()
{
char handle[100];
int size;
char y;
do
{
while(1)
{
printf("Enter the size of the array\n");
fgets(handle,sizeof(handle), stdin);
if(sscanf(handle, "%d",&size))
break;
printf("You did not enter a valid number\n");
}
int in [size];
int sum=0;
for(int i=0;i<size;i++)
{
while(1)
{
printf("Enter the next number in the array\n");
fgets(handle, sizeof(handle), stdin);
if(sscanf(handle,"%d",&in[i]))
break;
printf("You did not enter a valid number\n");
}
sum+=in[i];
}
int out[size];
printf("The Numbers now in the array are: ");
for(int i=0;i<size;i++)
{
out[i]=sum-in[i];
printf("%d, ",out[i]);
}
printf("\n");
printf("would you like to run this again?(y/n)\n");
scanf("%c",&y);
fgets(handle, sizeof(handle), stdin);
}while((y=='y')||(y=='Y'));
return 0;
}