以及我正在做這個功課,但我仍然沒有查看故障...當我運行(編譯後無gcc中的錯誤)似乎工作正常.. 。但是當我把輸入,即「254 34 199」的輸出返回:「有兩個相同的數字,再試一次」......根本不是邏輯。輸出仍然沒有在所有的整數值邏輯
有什麼問題?
謝謝!
#include<stdio.h>
int main()
{
puts("Enter three numbers separated by a space to determine what is the greatest, what is the one in the middle and what is the lowest.");
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
int imax(int a, int b) {return a < b ? b : a;}
int imin(int a, int b) {return a < b ? a : b;}
int high = imax(imax(a, b), c);
int low = imin(imin(a, b), c);
int mid(int a, int b, int c) {
if (a<b && a>c) return a;
else if (b<a && b>c) return c;
else return b;
}
if (high == mid && mid == low) puts("All of the numbers are equal. Try again");
else if (high == mid || high == low || mid == low) puts("There's two equal numbers. Try again"); /* This else if makes me crazy cause is not logic with a lot of combinations of three numbers! */
else printf("The greatest are %d, the middle are %d and the lowest are %d\n", high, mid, low);
}
編譯?你最好打開更多的警告,然後......(gcc上的'-Wall')。不應允許在其他函數中定義函數。 – Thomas 2012-03-25 09:50:14
@Thomas這是一個被濫用的gcc擴展。 – cnicutar 2012-03-25 09:51:46
@Thomas,更好的辦法是添加'-std = c99'或類似的東西。 – 2012-03-25 10:51:38