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

来源:百度知道 编辑:UC知道 时间:2024/05/07 05:02:17
实现10个数之间大小的比较,输出最大值和最小值

#include<stdio.h>
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<min) min=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.

int a[10],t;
for(int i=0;i<9;i++)
for(int j=1;j<10;j++)
{a[i]=a[i]>a[j]