1. 程式人生 > >5個數求最值

5個數求最值

color nbsp pro 數據 display log c語言 五個 描述

http://acm.nyist.net/JudgeOnline/problem.php?pid=31

c語言書上的題目

描述
設計一個從5個整數中取最小數和最大數的程序
輸入
輸入只有一組測試數據,為五個不大於1萬的正整數
輸出
輸出兩個數,第一個為這五個數中的最小值,第二個為這五個數中的最大值,兩個數字以空格格開。
樣例輸入
1 2 3 4 5
樣例輸出
1 5
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int a[5];
 5     int min=0;
 6     int max=0;
 7     for(int t=0;t<5;t++)
8 scanf("%d",&a[t]); 9 for(int t=1;t<5;t++) 10 { 11 if(a[max]<a[t])max=t; 12 if(a[min]>a[t])min=t; 13 } 14 printf("%d %d",a[min],a[max]); 15 }

5個數求最值