/* C program to find maximum between two numbers using switch case */
#include <stdio.h>
void main() {
int m, n;
printf("\nEnter the first number\n");
scanf("\n%d", &m);
printf("\nEnter the second number\n");
scanf("\n%d", &n);
switch (m > n) { /* it will give result either as 0 or 1*/
case 0:
printf("\nThe greater number is %d\n", n);
break;
case 1:
printf("\nThe greater number is %d\n", m);
break;
default:
printf("\nBoth number's are same\n");
}
}
switch
に条件がブール値であるというエラーが表示されます。スイッチケースを使用して2つの数値の間で最大値を見つけるCプログラム
私が間違っていますか?
どのgccのバージョンを使用していますか?私の4.8.4はエラーがないので。 –
MSVCが警告を出します。値は 'true'である必要はありません。 '0'は偽であり、他の全ての値は'真 'である。あなたは安全に 'true'が' 1'と仮定することはできません。たとえば、 'int apples = 5; if(apples){}; 'がtrueに評価され、明らかに' 1'ではありません。 –
_printf( "\ n大きい数字は%d \ n"、n); _これは等しい場合は偽のステートメントです。とにかく、正しいツールを選択しました。この場合、if文になります。 –