题解 | #多组_一维数组_T组形式#
多组_一维数组_T组形式
https://www.nowcoder.com/practice/90cdc8e31ef74b6e9fd44c1e03077b57
#include <stdio.h>
#include <stdlib.h>
long long int sum(long long int *arr, int len) {
long long int total = 0;
for (int i = 0; i< len; i++) {
total += arr[i];
}
return total;
}
void inputAndPrintForEachGroup(int n) {
long long int *a = (long long int*)malloc(n * sizeof(long long int));
for (int i= 0; i < n; i++) {
scanf("%lld", &a[i]);
}
printf("%lld\n", sum(a, n));
free(a);
}
int main() {
int t;
scanf("%d\n",&t);
while( t > 0) {
int temp;
scanf("%d\n", &temp);
inputAndPrintForEachGroup(temp);
t --;
}
}
