题解 | #多组_一维数组_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 --;
    } 

}




全部评论

相关推荐

我:“加班需要有加班工资。”&nbsp;hr:“为什么?”&nbsp;哈哈哈哈哈哈哈离大谱
juntenor:你确实太理想化了,对社会不了解呀。这个和HR没有关系,这是国内特色,不然怎么还会有外包就这种逆天的存在呢。
点赞 评论 收藏
分享
头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务