標題:

C++語言程式

發問:

在畫面上依序印出這 40 個數 (1) 每一列印 10 個數, 共計 4 列 (2) 每一行的數字都要排列整齊 1585 660 1155 442 486 1101 314 1564 194 1144 1576 419 572 43 478 77 605 1076 1992 109 1114 288 1970 811 1811 7975 946 354 1854 713 1301 1894 1326 639 210 1462 1670 954 1864

最佳解答:

 

此文章來自奇摩知識+如有不便請留言告知

#include #include int main() { int i,a[40]={1585,660,1155,442,486,1101,314,1564, 194,1144,1576,419,572,43,478,77, 605,1076,1992,109,1114,288,1970,811, 1811,7975,946,354,1854,713,1301, 1894,1326,639,210,1462,1670,954,1864,0 }; for(i=1;i<=40;i++) { printf("%6d",a[i-1]);//%6d..6控制間格寬度 if(i%10==0)printf(" ");//i是10的倍數時 換行 } system("pause"); return 0; }

其他解答:

#include #include using namespace std; int main() { int a[40]={1585, 660, 1155, 442, 486, 1101, 314, 1564, 194, 1144, 1576, 419, 572, 43, 478, 77, 605, 1076, 1992, 109, 1114, 288, 1970, 811, 1811, 7975, 946, 354, 1854, 713, 1301, 1894, 1326, 639, 210, 1462, 1670, 954, 1864}; for(int i=0; i<40; i++) { if(i>0 && i%10==0) { cout << endl; } cout << setw(6) << a[i]; } cout << endl; system("pause"); } 你給的數字只有39個喔 找到缺哪個數字補進去就好了481517FD598DAD6B
arrow
arrow

    wszspj2 發表在 痞客邦 留言(0) 人氣()