*動態數組使用
資源限制
時間限制:1.0s 內存限制:512.0MB
從鍵盤讀入n個整數,使用動態數組存儲所讀入的整數,並計算它們的和與平均值分別輸出。要求儘可能使用函數實現程序代碼。平均值爲小數的只保留其整數部分。
樣例輸入:
5
3 4 0 0 2
樣例輸出:
9 1
樣例輸入:
7
3 2 7 5 2 9 1
樣例輸出:
29 4
/*
Name: 藍橋杯:動態數組使用
Copyright: 拔劍四顧心茫然
Author: 拔劍四顧心茫然
Date: 20/04/16 18:24
Description: dev-cpp 5.11
*/
#include<iostream>
using namespace std;
int count(int a[], int n)
{
int sum,avg;
for(int i=0;i<n;i++)
sum += a[i];
avg = sum / n;
cout << sum << " " << avg;
return sum;
}
int main()
{
int n,temp;
int *a = new int [n];
cin >> n;
for(int i=0;i<n;i++)
cin >> a[i];
count(a,n);
delete [] a;
return 0;
}
不知道爲什麼不能通過藍橋杯官網的測試,還望大神指點迷津