close
標題:
初學者請教一段c語言代碼
發問:
#includeint main(void){ int row; int col; char cc; printf("Enter a CHAR:"); scanf("%c",&cc); for(row = 1; row <=10; row++) { for(col = 1; col <=row; col++) { printf(" %c ",cc); } ... 顯示更多 #include int main(void) { int row; int col; char cc; printf("Enter a CHAR:"); scanf("%c",&cc); for(row = 1; row <=10; row++) { for(col = 1; col <=row; col++) { printf(" %c ",cc); } printf("
"); } } 以上為什麼運行後會顯示為三角形?
最佳解答:
其他解答:
初學者請教一段c語言代碼
發問:
#include
最佳解答:
此文章來自奇摩知識+如有不便請留言告知
for(row = 1; row <=10; row++) { for(col = 1; col <=row; col++) { printf(" %c ",cc); } printf(" "); } Because when the row variable varies from 1 to 10, the col variable of each row varies from 1 to the value of row. That means in the first row, row = 1, so col variable could only be 1 and output only one character For second row, row=2 so col varies from 1 to 2 and then output 2 characters. Similarly, 3rd row output 3 characters...etc. It then forms a triangle with one character at the top and 10 characters at the bottom.其他解答:
文章標籤
全站熱搜
留言列表