http://www.blueshop.com.tw/board/FUM20050124191259IGD/BRD200604022103422A7.html

https://www.onlinegdb.com

用C求最大值最小值

//這是我寫的,給你參考
#include <stdio.h> 
#include <float.h>
#include <stdlib.h>

int main() 
{     
	float A[20],a_max=FLT_MIN,a_min=FLT_MAX; 
	int i,s; 
	 
    while(1){
   	   	printf("請輸入陣列的個數(小於20):\n"); 
		scanf(" %d",&s);
        if(s>0 && s<20)
			break;
    }
	printf("請輸入陣列各數值\n");    
	for(i=0;i<s;i++){
		printf("A[%d]=",i); 
		scanf(" %f",&A[i]);
		if(A[i]>a_max) a_max=A[i];
		if(A[i]<a_min) a_min=A[i];
	}
	
	printf("A陣列最大值= %f\n",a_max); 
	printf("A陣列最小值= %f\n",a_min); 
	 
	system("PAUSE");
	return 0; 
}
arrow
arrow

    JL8051 發表在 痞客邦 留言(0) 人氣()