用函数编写一个程序求两个数的和与积

来源:百度知道 编辑:UC知道 时间:2024/07/02 14:48:06

不知道你用的是什么语言,我用C++编的
#include<iostream.h>
void get(int a,int b,int &c,int &d)
{
c = a+b;
d = a*b;
}
void main()
{
int a,b,c,d;
a=20,b=30;
get(a,b,c,d);
cout<<c<<" "<<d<<endl;
}

Pascal程序:
var a,b:longint;
begin
readln(a,b);
write(a+b,a*b);
end.
C程序:
#include<stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
printf("%d %d",a+b,a*b);
return 0;
}

c语言
#include<stdio.h>
int he(int a,int b)
{
return a+b;
}
int ji(int a,int b)
{
return a*b;
}

VB的

function he(a,b)
he=a+b
end function
function ji(a,b)
ji=a*b
end function