代碼接受一個數字作爲輸入,並返回一個數輸出根據給定的系列:解決烏托邦樹,代碼有什麼問題?
輸入
1 2 3 4 5 6 7 8 9
輸出
2 3 6 7 14 15 30 31 62
守則
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int test,y[10],i,j,newvalue = 0;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
scanf("%d\n",&y[i]);
for (j=0 ; j<=y[i] ;j++)
{
if (j %2 ==0)
newvalue =newvalue +1;
else
newvalue = newvalue*2;
}
printf("%d\n",newvalue);
}
return 0;
}
首先請告訴我們,什麼是錯的輸出。 – Pieter21 2014-08-27 09:09:05
它編譯?它會崩潰嗎?它會輸出錯誤嗎?怎麼了? – 2014-08-27 09:12:58
我猜測給定的輸入條件中,代碼'test'變量的輸入缺失,必須是9! – 2014-08-27 09:13:42