可以这么写
#include<iostream>using namespace std;
int cala(int x);
int cala(int x, int y);
int cala(int x, int y, int z);
int main()
{
int a, i = 0;
cout << "请输入x或者x y或者x y z" << endl;
while (1)
{
cin >> a;
i++;
if (cin.get() == '\n')
{
break;
}
}
switch (i)
{
case 1:
cout << cala(a) << endl;
break;
case 2:
cout << cala(a, a) << endl;
break;
case 3:
cout << cala(a, a, a) << endl;
break;
default:
break;
}
}
int cala(int x)
{
return (x * x);
}
int cala(int x, int y)
{
return (x * y);
}
int cala(int x, int y, int z)
{
return (x + y + z);
}
页:
[1]