#include<stdio.h>
int sum(int array[],int n)
{ int i,s=0;
for(i=0;i<n;i++)
s+=array[i];
return s;
}
void main()
{ int num,a[10]={1,2,3,4,5,6,7,8,9,10};
scanf("%d",&num);
printf("%d\n",sum(a,num));
}
编程题:已知一个一维数组,求其中前n个数的和。n由键盘输入,布布扣,bubuko.com
时间: 2024-10-05 05:58:17