C语言:实现10个数之间大小的比较,输出最大值和最小值

实现10个数之间大小的比较,输出最大值和最小值
2025-04-01 01:05:49
推荐回答(2个)
回答1:

#include
void main()
{ int max,min,x,n;
printf("please input the first number:");
scanf("%d",&x);
max=min=x;
for(n=2;n<=10;n++)
{printf("please input the %d number:",n);
scanf("%d",&x);
if(x>max) {max=x;continue;}
if(x }
printf("the biggest number is:%d;the smallest number is:%d.\n",max,min);
}
//运行结果:
please input the first number:5
please input the 2 number:5
please input the 3 number:5
please input the 4 number:1
please input the 5 number:5
please input the 6 number:4
please input the 7 number:7
please input the 8 number:8
please input the 9 number:9
please input the 10 number:9
the biggest number is:9;the smallest number is:1.

回答2:

int a[10],t;
for(int i=0;i<9;i++)
for(int j=1;j<10;j++)
{a[i]=a[i]>a[j] ? (t=a[i];a[i]=a[j];a[j]=t) }
printf("max: %d",a[9]);
printf("min: %d",a[0]);