瀏覽單個文章
8:5
Major Member
 

加入日期: Dec 2002
您的住址: 謎
文章: 265
看來大家都喜歡把輸入第一第二個數字也放在迴圈裡,而且也不喜歡直接從迴圈內 break 出來?

代碼:
#include <stdlib.h>
#include <limits.h>
main() {
int max1=INT_MIN, max2=INT_MIN, n;
        printf("enter at least two non-zero numbers then end with a zero...\n");
        while (scanf("%d", &n), n!=0) {
                if (n>max1) {
                        max2=max1;
                        max1=n;
                } else if (n>max2) {
                        max2=n;
                }
        }
        printf("max1=%d, max2=%d\n", max1, max2);
}
舊 2004-10-29, 12:57 AM #26
回應時引用此文章
8:5離線中