所以我正在编写这个程序,完成后,我尝试运行它,但由于某种原因,控制台上没有任何显示。我多次查看代码并尝试了多种方式来执行相同的功能,基本上是不断从用户那里获取输入,直到他/她输入0,然后显示最大和第二大的数字,如果用户输入0并且没有可用的号码,然后继续检查。我认为可能存在无限循环或其他问题。这是代码:
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
void main()
{
int input,z;
int large,small,counter=0;
bool a=false;
while (1){
if(scanf("%d\n",&input)>0)
{
small=input;
counter++;
if(small>large)
{
z=small;
small=large;
large=z;
}
}
else if(scanf("%d\n",&input)<0)
{
printf("Please enter a positive value\n");
}
else if(scanf("%d\n",&input)==0)
{
if(small>0 && large>0)
{
printf("There are in total %d positive integers entered",counter);
printf("The largest number is %d, while the second largest is %d", large,small);
a=true;
break;
}
else
{
printf("You have to enter atleast two positive integers");
}
}
}
}
任何形式的帮助将不胜感激,谢谢。