# GTHER – EDITORIAL

Tester and Editorialist: tejaram15

and Practice

CAKEWALK

Array

### PROBLEM:

Given an array of integers [A1,A2,…An] you need to find sum of all other indices of the given array excluding the current one.

### EXPLANATION:

Simply think that you need to find the number of candies that all other students have in your class the there are two different approaches…
• Count for every student the number of chocolates and display it.
• Alternatively, you can sum all the values together and display the sum excluding the sum of the present student.
```  #include "stdio.h"
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int a[n+1];
long int sum=0;
for(int i=0;i<n;i++) scanf("%d",&a[i]),sum+=a[i];
for(int i=0;i<n;i++) (i==n-1)?printf("%ld\n",sum-a[i]):printf("%ld ",sum-a[i]);
}
return 0;
}```
• In C/C++ you can’t declare an array with a variable number of index.
It uses static memory location (basic level).So error is due to the declaration of the array a[n+1].
Declare the array with a numeric value.

//