0

The aim of the program is to add ten numbers then output their sum. I can do this but in a very basic way. for instance the only way I know how to do this is by adding each array and thats quite tedious and long is there any way of shortening this to a simpler form please help thanks. THE PROBLEM IS WITH THE COMMENTED LINE.

THIS IS THE WHILE LOOP:

```
#include <stdio.h>
#include "simpleio.h"
int main()
{
int i;
int arr[10];
int sum;
i=0;
while(i<10)
{
arr[i]=getInt();
i++;
sum = arr[1]+arr[1]+arr[2]...;//HOW DO I MAKE THIS SIMPLER?
}
printf("The sum is %d \n",sum);
return 0;
}
```

THIS IS THE FOR LOOP:

```
#include <stdio.h>
#include "simpleio.h"
int main()
{
int i=0;
int arr[i];
int sum;
printf("Please enter 10 numbers: \n");
for(i=0;i<10;i++)
{
arr[i] = getInt();
sum = arr[0] + arr[1] + arr[2]+arr[3]+arr[4]+arr[5]+arr[6]+arr[7]+arr[8]+arr[9]; //how do I SIMPLIFY THIS LINE!
}
printf("The sum is %d \n",sum);
return 0;
}
```

*Edited 6 Years Ago by Don_k*: n/a