Sum of array

QUESTION

Given an array of N integers. Your task is to print the sum of all of the integers.\n\nInput: \nFirst line of input file contains a single integer T which denotes the number of test cases. Then, T test cases follow. First line of each test contains a single integer N which denotes the number of elements in an array. Second line of each test case contains N space separated integers denoting the elements of an array.\n\n\nOutput:\nCorresponding to each test case, print the sum of array in a new line.\n\nConstraints:\n1<=T<=100\n1<=N<=1000.

“TESTCASE_1”: “2\n4\n1 2 3 4\n6\n5 8 3 10 22 45\n###—###SEPERATOR—###—\n10\n93”, “TESTCASE_2”: “2\n6\n10 20 30 40 50 60\n3\n99 88 77\n###—###SEPERATOR—###—\n210\n264”, “TESTCASE_3”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <stdio.h>
int main()
{
int t;
  scanf("%d",&t);
  while(t--)
  {
    int n,i,sum=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    {
      scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
      sum+=a[i];
    }
    printf("%d\n",sum);
    sum=0;
  }
	return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro