我无法在我的程序中找到正确的输出,以找出三个数字中的第二大数字。 (我知道这是非常基本的,但我刚刚开始学习C,所以任何帮助和提示将不胜感激!)在我的程序中,我得到了三个数字中的最大值和最小值(但没有问题),但我一直在第二大的答案204。 (这是错误的!)这是我的代码,对不起,如果有任何可怕的错误,就像我说的,我是新手!非常感谢! :)我一直得到不正确的输出为我的第二大号码程序(C程序)
//include the libraries
#include <stdio.h>
#include <conio.h>
//include the main function
int main()
{
//declare the variables
long a,b,c,min,max,secmax;
//read the variables
printf("a=");scanf("%ld",&a);
printf("b=");scanf("%ld",&b);
printf("c=");scanf("%ld",&c);
// Find the min of the 3 numbers.
if(b>a && c>a)
{
min=a;
}
else
{
min==b || min==c;
}
if(a>b && c>b)
{
min=b;
}
else
{
min==a || min==c;
}
if(a>c && b>c)
{
min=c;
}
else
{
min==a || min==b;
}
// Find the max of the 3 numbers.
if(b>a && b>c)
{
max=b;
}
else
{
max==a || max==c;
}
if(a>b && a>c)
{
max=a;
}
else
{
max==b || max==c;
}
if(c>a && c>a)
{
max=c;
}
else
{
max==a || max==b;
}
//Find the second largest number
if(a!=max && a!=min)
{
a=secmax;
}
else
{
b==secmax || c==secmax;
}
if(b!=max && b!=min)
{
b=secmax;
}
else
{
a==secmax || c==secmax;
}
if(c!=max && c!=min)
{
c=secmax;
}
else
{
b==secmax || a==secmax;
}
//print the output
printf("\nThe maximum is %d\n",max);
printf("\nThe second largest number is %d\n",secmax);
printf("\nThe minimum is %d\n",min);
getch();
return 1;
}
什么输入你给它?此外,这些代码块:'else { min == b ||分钟==℃; “对我没有意义。 – nhgrif
我输入a = 3,b = 5和c = 8。好的,我应该把它们全部拿出来吗? :) – Eleanor
基于'a = 3','b = 5','c = 8',它告诉你'204'是第二大的数字......? – nhgrif