當我嘗試與stdinput-這段代碼爲什麼會給出意想不到的結果?
4
1
8
26
52
輸出I得到爲 -
1
6
12
12
代替0 1 6 12運行此片的代碼 -
#include<iostream>
#include<stdio.h>
using namespace std;
long long fact(long long k)
{ return k/5 + k/25;
}
int main()
{
long long n,k;
scanf("%lld %lld", &n,&k);
while(n--)
{
scanf("%lld",&k);
printf("%d\n",fact(k));
}
}
。
有人可以解釋這個意外的結果嗎?
爲什麼不逐行通過您的算法逐行在紙上找出? :)是不是第一個'scanf'調用可疑?你從不在一行中輸入兩個數字。對於我所知道的,這是有效的,因爲我不使用像'scanf'這樣古老而過時的技術。 –
我也嘗試過使用'cin cout'而不是'scanf printf',但代碼仍然失敗 – Backspace
現在應該開始學習如何使用調試器了。 –