不限制语言,在控制台输入“[参数1]函数名[参数2]”,也即有一个参数在函数名之前输入,如何实现?
参考如下:
#include <stdio.h>
#include <string.h>
void fun1(int a,int b)
{
printf("%d+%d=%d\n",a,b,a+b);
}
void fun2(int a,int b)
{
printf("%d*%d=%d\n",a,b,a*b);
}
int main()
{
int a,b;
char buf[20]={0};
scanf("%d%s%d",&a,buf,&b);
if(strcmp(buf,"fun1")==0)
fun1(a,b);
else if(strcmp(buf,"fun2")==0)
fun2(a,b);
else
printf("no function find\n");
return 0;
}
c 语言的话去了解一下scanf
Python 了解下 input