#include <stdio.h>
main()
{
float data1,data2,m;
char op;
printf("Please input data1 and data2\n");
scanf("%f%c%f",&data1,&op,&data2);
switch(op)
{
case'+':m=data1+data2;printf("%f\n",m);break;
case'-':m=data1-data2;printf("%f\n",m);break;
case'*':m=data1*data2;printf("%f\n",m);break;
case'/':m=data1/data2;
{
if(data2==0)printf("error!\n");
else printf("%f\n",m);break;
}
default:printf("error!\n");
}
}
我初学C语言,也不知道写的对不对(但是能运行一些简单的)。不对的地方还请各位前辈多多指教!