因为计算机的运行速度过快,C语言只运行一下就消失了。你可以采用以下方式;
#include<cstdlib>
#include<cstdio>
int main(){
int a,b;
scanf("%d%d",&a,&b);
printf("%d\na+b);
system("pause");//或while(1);
return 0;
}
其中#include<cstdlib>与system("pause")是一对,而while(1);则不需要特殊头文件.
运行结果如下
如果程序没有问题,那就是编译器的问题:
解决方案有两种:
1.主函数的结束位置加system("pause");同时需要请引入头文件:#include<stdlib.h>
例如:
#include<stdlib.h>2.主函数的结束位置加getchar();同时需要引入头文件:#include<string.h>
例如:
#include<string.h>