以下代码打印输入数字的最大值和最大负值(如果我们有 -10 和 -5,则 -5 更大)直到达到一个符号。我的问题是是否有更好的方法来找到最大的负值(避免 INT_MIN 或其他此类笨拙的方法)。
#include <stdio.h>
#include <conio.h>
#include <limits.h>
int main()
{
float max=0, n, bnn=INT_MIN;
while(1){
printf("Enter an integer:");
if(scanf("%f", &n)!=1){
break;
}
if (n>max)
max=n;
else if(n>=bnn)
bnn=n;
}
printf("The maximum number of the entered ones is:%0.2f\n", max);
printf("The biggest negative number is:%0.2f", bnn);
getch();
}
最佳答案
从 0.0 开始 bnn
if ((n < 0) && ((bnn == 0.0) || (n > bnn)))
bnn = n;
关于c - 查找最大和最大负数的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21005603/