资源限制
时间限制:1.0s 内存限制:512.0MB
从键盘读入n个整数,使用动态数组存储所读入的整数,并计算它们的和与平均值分别输出。要求尽可能使用函数实现程序代码。平均值为小数的只保留其整数部分。
样例输入:
5
3 4 0 0 2
样例输出:
9 1
样例输入:
7
3 2 7 5 2 9 1
样例输出:
29 4
之前一直都是用静态数组,这次题目要求动态数组
//动态数组使用
#include <stdio.h>
#include <stdlib.h>
int main(){
int n,i,s=0;
scanf("%d",&n);
int *a;
a=(int *)malloc(sizeof(int)*n);//申请动态数组,长度为n
for(i=0;i<n;i++){
scanf("%d",&a[i]);
s+=a[i];
}
printf("%d %d",s,s/n);
return 0;
}```