自定義函式初步瞭解
阿新 • • 發佈:2019-02-13
#include<stdio.h>
int main(){
int i,j,x,y,z;
printf("input 3 numbers:\n");
scanf("%d %d %d",&x,&y,&z);
i=MAX(x,y,z);
j=MIN(x,y,z);
printf("MAX is %d,MIN is %d",i,j);
return 0;
}
int MAX(int a,int b,int c){
return a>b?a>c?a:c:b>c?b:c;
/*條件1?條件2?結果1:結果3:條件3?結果2:結果3 */
}
int MIN(a,b,c){
return a<b?a<c?a:c:b<c?b:c;
}
//形參實參傳遞
#include<stdio.h>
int main(){
int a;
printf("input a number:\n");
scanf("%d",&a);
printf("%d",X(a));
return 0;
}
int X(int a){
int i;
for(i=a-1;i>0;i--){
a+=i;
}
return a;
}