Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 1 decade ago

FOR迴圈

我要寫出b[10]={0}

c[10]={0}

b[0]=c[0]

b[1]=c[0]+c[1]

b[2]=c[0]+c[1]+c[2].....

請問迴圈要如何設定(或是有其他方法)???

1 Answer

Rating
  • 1 decade ago
    Favorite Answer

    b[10] = {0,1,2,3,4,5,6,7,8,9}; //初始化 b 陣列

    c[10] = {0}; //初始化 c 陣列

    int i, j;

    for(i=0;i<10;i++)

    {

    for(j=0;j<=i && j<10;j++)

    {

    c[i] += b[j]; //計算 c 陣列 的元素

    }

    }

    結果;

    c[0] = 0;

    c[1] = 0+1;

    c[2] = 0+1+2

    c[3] = 0+1+2+3

    c[4] = 0+1+2+3+4

    c[5] = 0+1+2+3+4+5

    c[6] = 0+1+2+3+4+5+6

    c[7] = 0+1+2+3+4+5+6+7

    c[8] = 0+1+2+3+4+5+6+7+8

    c[9] = 0+1+2+3+4+5+6+7+8+9

Still have questions? Get your answers by asking now.