C++問題倒正三角形以for迴圈
使用者輸入一個正整數
然後輸出以*印成的倒 正三角形(用for迴圈來做)
EX:
輸入5
輸出的東西
*****
***
*
寫了兩個不同的程式語言
重點是如何控制空白及*數量
C++
我是以階層iLevel來設定比較單純
你要5個*需要設定3層
int iLevel=3;
for(int i = iLevel-1 ; i <=0 ; i--)
{
repeat(iLevel-i," ") ;
repeat(1+(i)*2, "*") ;
repeat(iLevel-i," ") ;
printf("\n");
continue;
}
//自行定義一個repeat 數量,字的function
function repeat void repeat(int n,char ch)
{
for(int i=0;i<n;i++) printf("%c",ch);
}
ASP寫法
<%
iLevel=7
For i=iLevel-1 To 0 Step -1
Response.write String(iLevel-i," ") & String(1+(i)*2, "*") & String(iLevel-i," ") & "
"
Next
%>
搜尋
倒正三角形以For迴圈
張貼者:
Godhelp
at
2009年10月29日 星期四
0 意見:
張貼留言