-4
每當我嘗試運行程序時,我得到的唯一輸出是來自表達式else,即使條件匹配,if語句也會被忽略。什麼是我的錯誤?` 繼承人關於在c編程中if和else表達式的問題
#include <stdio.h>
#include <math.h>
void main()
{
int a,b,c=0,d,e,f,g,s=0,h,i;
printf("Enter the lower limit a\n");
scanf("%d",&a);
printf("Enter the upper limit b\n");
scanf("%d",&b);
for(e=a;e<=b;e++)
{
f=e;
do{
f=f/10;
c++;
}while(f!=0);
g=e;
do{
d=g%10;
s=s+pow(d,c);
g=g/10;
}while(g!=0);
if(s==e){
h=s;
printf("\nThe number %d is an armstrong number\n",h);
}
else{
i=e;
printf("\nThe number %d is not an armstrong number\n",i);
}
}
}
使用gcc在ubuntu上編譯它 –
您需要在每個循環中重置一些變量。 – BLUEPIXY
當您逐步完成代碼時,調試器會告訴您什麼?如果你還沒有學會使用,現在是完美的時機。作爲一名開發人員,如何使用調試器來追蹤程序的流程並檢查變量的值,沒有更多的寶貴技能。 (你現在也應該學會使用更好的變量名稱和空白空間,閱讀充滿's = s + pow(d,c)'的代碼;'埋在許多其他'a = z; y = r ++中;如果(a == rz * x){}'是非常困難的,那麼我的商店中的代碼會導致編碼人員需要找到新的工作。) –