[英]what is wrog with this basic if code for finding the smallest number writen
#include <stdio.h>
int main(int argc, char **argv)
{
float A,B,C;
printf("pls write a 3 numbers\n");
scanf("%f%f%f",&A,&B,&C);
if (%f<(%f||%f),A,B,C)
{printf("NO A");}
else if(%f<(%f||%f),B,C,A)
{printf("NO C");}
else if (%f<(%f||%f),C,B,A)
{ printf("NO B");}
return 0;
}
我無法修復此代碼我不知道為什么它可以正常工作它有一個非常簡單的解決方案但我是初學者。如果我無法修復它們,就會出現一些問題。
if (%f<(%f||%f),A,B,C)
這不是比較數字的正確語法。 事實上,你只能用一個運算符比較 2 個數字。
要比較您需要的 3 個數字
if (A>B)
{
if (A>C)
{
printf("no A");
}
else
{
printf("no C");
}
}
else
{
if (B>C)
{
printf("no B");
}
else
{
printf("no C");
}
}
您在條件語句中使用了 % 符號。 %f 是格式說明符,用於定義要從標准輸入中獲取的數據類型(此處為浮點數)。 這就是為什么它只在 scanf() 中使用。 main() 是一個內置函數。 你不應該在那里定義任何東西! 希望下面的代碼對你有幫助。
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c;
printf("Enter three numbers");
scanf("%f %f %f",&a,&b,&c);
if((a>b) && (a>c))
printf("\n a is greater");
else if(b>c)
printf("\n b is greater");
else
printf("\n c is greater"); // if the above doesn't work, automatically c is greater.
getch(); //get the output directly
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.