问题需要解决,谢谢了

来源:百度知道 编辑:UC知道 时间:2024/05/10 14:38:56
编写一个录入函数:用来从键盘接收n个整型数并存放在一个整型数组中.在主函数中调用该函数计算出这n个整数之和.

我也有一个
在linux下运行一切正常
刚在windows下运行报错,所以修改了一下
void main()
{
int n ;
int s ;
printf("please input n: ");
scanf("%d",&n);
s=sum(n);
printf("the total is : %d\n",s);
}
int sum(int n)
{
int x[100];
int i=0;
int total = 0;
for(i=0;i<n;i++)
{
printf("please input the number %d:",i+1);
scanf("%d",&x[i]);
total+=x[i];
}
return total;
}

#include <iostream>

int func(n){
int temp;
int arr[n];
int i = 0;
std::cout<<"请输入"<<n<<"个整数:"<<std::endl;
while(i < n){
std::cin>>temp;
arr[i] = temp;
i++;
}
int result;
for(i = 0; i < n; i++){
result += arr[i];
}
return result;
}
int main){
const int MAX = 10; //随你改成多少
std::cout