當前位置:聚美館>智慧生活>心理>

c語言求最大值函數

心理 閱讀(1.38W)
c語言求最大值函數

c語言求最大值的函數有

#include"stdio.h"

voidInput_Max_Min(int*p,int*pl,int*ps){

inti

printf("Pleaseenterthe10Numbers...n")

for(*pl=*ps=i=0i<10i++){//輸入10個整數並判斷大小

scanf("%d",p+i)

if(p[i]<p[*ps])//

*ps=i

if(p[i]>p[*pl])//

*pl=i

}

}

intmain(intargc,char*argv[]){

intm[10],ml,ms

Input_Max_Min(m,&ml,&ms)//用數組首址和最大值及最小值位置記錄變量地址調用自訂函數

printf("TheMAXism[%d]==%dnTheMINism[%d]==%dn",ml,m[ml],ms,m[ms])//輸出結果

return0

}