#11481: 為什麼都printf不出來


qwerty123457 (ji3cl3gj94)


#include<stdio.h>
int main()
{
int n,m,a;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int t=n;t>m;){
if(t<=m)
{
n=n+1;
t=t+n;
a++;

}
else{
printf("%d",a);
}
}
a=0;
}
}

#11516: Re:為什麼都printf不出來


jack60126 (hadman)


 



你的邏輯概念沒釐清

這段程式碼 t>m的情況 就已經跳出for loop了

你的printf 在 for  loop裡面 所以不會被執行到

#include<stdio.h>

#include<stdlib.h>

 

int main(){

int start,end,sum;

int count=0;

scanf("%d%d",&start,&end);

 

for(int i=start; sum<=end ;i++){

sum+=i;

count++;

}

printf("%d\n",count);

return 0;

}

可以給你參考一下

還有給你一點建議 變數的命名 取的有異議一點 會比較方便你看到你的錯誤

也方便別人幫你debug