switch case问题

来源:百度知道 编辑:UC知道 时间:2024/05/04 06:13:13
#include <stdio.h>
#include <conio.h>
void main()
{
float a,b,c,max,med,min;
printf("Please input three unequal numbers, and I will compare them for you:\n");
loop:scanf("%f%f%f",&a,&b,&c);
switch (float a,float b,float c)
{
case a==b||b==c||c==a:
printf("There are at least two numbers are equal,please press Enter and input again!\n");
getch();
goto loop;
case a>b && b>c:
max=a;
med=b;
min=c;
break;
case b>a &&a>c:
max=b;
med=a;
min=c;
break;
case a>c && c>b:
max=a;
med=c;
min=b;
break;
case b>c && c>a:
max=b;
med=c;
min=a;
break;
case c>a && a>b;
max=c;
med=a;
min=b;
break;
case c>b && b>a;
max=c;
med=b;

这题其实用不到 switch ,用switch 会更麻烦一些

改了下你下面的问题
#include <stdio.h>
#include <conio.h>
void main()
{
float a,b,c,max,med,min;
printf("Please input three unequal numbers, and I will compare them for you:\n");
scanf("%f%f%f",&a,&b,&c);
while(a==b||b==c||a==c) //这里改成循环就行了
{
printf("There are at least two numbers are equal,please press Enter and input again!\n");
scanf("%f%f%f",&a,&b,&c);
}
if(a>b)
{
max=a;
min=b;
}
else
{
max=b;
min=a;
}
if(max<c)
{
med=max;
max=c;
}
else
{
if(max>c && c>min)
{
med=c;
}
else
{
med=min;
min=c;
}
}

printf("%f is the max, %f is the medium, %f is the min.\n",max,med,min);
getch();
}