main(){
int number1,number2,op;
printf("input two numbers:\n");
scanf("%d",&number1);
scanf("%d",&number2);
printf("*****************************************\n");
printf("*****************************************\n");
printf("** 1 - add **\n");
printf("** 2 - sub **\n");
printf("** 3 - mul **\n");
printf("** 4 - div **\n");
printf("*****************************************\n");
printf("*****************************************\n");
printf("please select(1-4):");
scanf("%d",&op);
if (op==1)
printf("result is :%d\n",number1+number2);
else if (op==2)
printf("result is :%d\n",number1-number2);
else if (op==3)
printf("result is :%d\n",number1*number2);
else if (op==4)
printf("result is :%d\n",number1/number2);
else
printf("没有这种运算!");
}
然后电脑提示:
D:\C语言\Microsoft Visual Studio\MyProjects\o\hhh\hhhjjjj.cpp(4) : error C2065: 'printf' : undeclared identifier
D:\C语言\Microsoft Visual Studio\MyProjects\o\hhh\hhhjjjj.cpp(5) : error C2065: 'scanf' : undeclared identifier
D:\C语言\Microsoft Visual Studio\MyProjects\o\hhh\hhhjjjj.cpp(30) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.
hhhjjjj.exe - 2 error(s), 1 warning(s)
但是老师在最前面加个#include <stdio.h>就可以运行了,这是为什么啊???
#include <stdio.h>
main(){
int number1,number2,op;
printf("input two numbers:\n");
scanf("%d",&number1);
scanf("%d",&number2);
printf("*****************************************\n");
printf("*****************************************\n");
printf("** 1 - add **\n");
printf("** 2 - sub **\n");
printf("** 3 - mul **\n");
printf("** 4 - div **\n");
printf("*****************************************\n");
printf("*****************************************\n");
printf("please select(1-4):");
scanf("%d",&op);
if (op==1)
printf("result is :%d\n",number1+number2);
else if (op==2)
printf("result is :%d\n",number1-number2);
else if (op==3)
printf("result is :%d\n",number1*number2);
else if (op==4)
printf("result is :%d\n",number1/number2);
else
printf("没有这种运算!");
}