引用 | 編輯
GNUGCC
2007-06-26 22:45 |
4樓
▲ ▼ |
可能是下面這個範例...
void Compare(int a, int b, int c) { int temp = 0; if ( a < b ) { temp = b; b = a; a = temp; } if ( a < c ) { temp = c; c = a; a = temp; } if ( b < c ) { temp = c; c = b; b= temp; } // 經過上面比較之後結果會由大到小排列 } x1 |
引用 | 編輯
karen7710
2007-06-27 19:12 |
5樓
▲ ▼ |
以下是完成後的程式,麻煩大大看看對不對!
內部我設的是77.5,可是輸出的卻是77.000,應該要如何更改呢? 複製程式 #include <stdio.h> #include <stdlib.h> void compare(float,float,float); float a=80.6,b=24.7; int main(void) { float c=77.5; compare(a,b,c); system("pause"); return 0; } void compare(float a, float b, float c) { int temp = 0; if ( a < b ) { temp = b; b = a; a = temp; } if ( a < c ) { temp = c; c = a; a = temp; } if ( b < c ) { temp = c; c = b; b= temp; } printf("排序後:%.3f %.3f %.3f\n",a,b,c); // 經過上面比較之後結果會由大到小排列 } x0 |
引用 | 編輯
gamewalk
2007-06-27 23:31 |
6樓
▲ ▼ |
複製程式
void compare(float a, float b, float c) { int temp = 0; // <--- 因為你說要浮點數這裡也要改成float if ( a < b ) { temp = b; b = a; a = temp; } if ( a < c ) { temp = c; c = a; a = temp; } if ( b < c ) { temp = c; c = b; b= temp; } printf("排序後:%.3f %.3f %.3f\n",a,b,c); // 經過上面比較之後結果會由大到小排列 } int temp改成 float temp ,GNUGCC大大是給int的例子給你看... x1 |