用函式找較大的值: //用函式輸出兩個數中較大的數
#include<stdio.h>
int max(int a,int b);
int main(){
int a,b; scanf("%d %d",&a,&b);
printf("較大的那個數是%d",max(a,b));
return 0;
} int max(int a,int b){
if(a>b){
return a;
}
else return b;
} 直接把比較的數放在函式里面比較 如果用單一出口的話,就: int max(int a,int b){ int c;//中間變數 if(a>b){ c=a; } else { c=b; } return c; }
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/51141.html
標籤:C
上一篇:eclipse 添加主題
