各位电脑高手,有关于C语言的问题想请教:编写一个函数实现将三个整数的和返回,应该如何编写啊?

来源:百度知道 编辑:UC知道 时间:2024/06/23 12:08:39

#include<stdio.h>
#define SIZE 3
main()
{
int a[SIZE];/*定义一个数组*/
int i=0,result;
for(i=0;i<SIZE;i++)
{
printf("Please input the numbers %d:",i);
scanf("%d",&a[i]);
}
result=add(a);
printf("The result is %d",result);
getch();
}
int add(int b[SIZE])
{
int j=0,temp=0;
for(j=0;j<SIZE;j++)
{
temp=temp+b[j];
}
return temp;
}
程序解释:用数组存储数据,传给add()函数做加和,返回加和结果。

int Add(int a;int b;int c)
{
return a+b+c;
}

int fun(int a,int b,int c)
{ return a+b+c;}

// Function return the sum of three integers
int sum(int a, int b, int c)
{
return a+b+c;
}
当然也可以用数组,但对于三个数,直接写还是挺方便的。