初级,这个程序有什么问题吗

来源:百度知道 编辑:UC知道 时间:2024/05/31 04:01:18
#include<stdio.h>
void main()
{
int a,b;
printf("please put two munbers:\n");
scanf("%d,%d",&a,&b);
if(a<b) printf("%d",a);
if(a>b) printf("%d",b);
}
运行输入两个数后就消失了
我打逗号了,也回车了。
还有一楼的,加了getch();后反而运行不了了,error C2065: 'getch' : undeclared identifier
我用的VC,加了,#include<conio.h> 还是不行

因为程序运行得太快了,所以你看不到结果
#include<stdio.h>
void main()
{
int a,b;
printf("please put two munbers:\n");
scanf("%d,%d",&a,&b);
if(a<b) printf("%d",a);
if(a>b) printf("%d",b);
getch();/* 加个这个就可以了 */
}

补充:请问你是用什么编译器呢,你加上#include <stdlib.h>和#include <conio.h>

是你没有注意输入的格式要求。你的输入是scanfa,&b); 请注意,"%d,%d",意思是输入两个整数,中间用逗号隔开。这个逗号就是问题所在,你输入的时候一定要在两个数中间加个逗号。这是格式的要求。事实上,更多的是写成scanf("%d%d",&a,&b);的形式,中间什么也没有,那么输入一个数,回车,再输入一个数就可以了。

不是getch();

正确的写法是:

getchar();

当然你一定要用getch();的话,那就在程序的第一行加入
#include<conio.h>

#include<stdio.h>
void main()
{
int a,b;
printf("please put two munbers:\n");
scanf("%d,%d",&a,&b);
if(a<b) printf("%d",a);
printf("%d",b);
}

加上一个头文件. ,#include<conio.h>