键盘接收数字进行调用计算源码:
#include"stdafx.h"
#include<iostream>
using namespace std;
int a1(int arg1, int arg2)
{
int s = arg1 + arg2;
return s;
}
int main()
{
int a; int b;
cout << "请输入数字进行计算:" << endl;
cin >> a;
cin >> b;
int s = a1(a, b);
cout << "计算结果为" << s << endl;
}
用调用进行大小比较源码:
#include"stdafx.h"
#include<iostream>
using namespace std;
int max(int x, int y) //调用将a,b两个值传送给x,y
{
int z;
if (x > y)
z = x;
else
z = y;
return z; //将z的值传送回去
}
int main()
{
int a; int b;
cout << "请输入数字进行大小比较:" << endl;
cin >> a;
cin >> b;
int z = max(a, b);
cout << "最大数字为" << z << endl;
}
改进版本:
#include"stdafx.h"
#include<iostream>
using namespace std;
int max(int x, int y) //接收a,b的值
{
/*int z;
if (x > y)
z = x;
else
z = y;
return z;*/ //将z的值传送回去
return x > y ? x : y;
}
int main()
{
int a; int b;
cout << "请输入数字进行大小比较:" << endl;
cin >> a;
cin >> b;
int z = max(a, b); //将a,b的值传送给x,y
cout << "最大数字为" << z << endl;
}
\