PCDVD數位科技討論區

PCDVD數位科技討論區 (https://www.pcdvd.com.tw/index.php)
-   疑難雜症區 (https://www.pcdvd.com.tw/forumdisplay.php?f=34)
-   -   誰可以幫我寫出一個簡單的程式....QQ~! (https://www.pcdvd.com.tw/showthread.php?t=465775)

vanness70087 2005-03-29 07:58 PM

誰可以幫我寫出一個簡單的程式....QQ~!
 
可以告訴我怎麼寫去下面那個程式嗎~???

*
**
***
****
*****
****
***
**
*

就是寫上面那個跑星星小程式.......用FOR回圈寫....@@
我只會寫出這樣
*
**
***
****
*****
這個的程式......在下面.......但是不會寫上面那個....
#include<stdio.h>
void main()
{
for (int i=1 ; i<=5 ; i++)
{
for (int j=1 ; j=i ; j++)
printf("*");
printf("\n");
}
getchar();

}

可否幫我一下~謝謝這邊的大大....!

airitter 2005-03-29 08:05 PM

如果i=5
j--

vanness70087 2005-03-29 08:16 PM

哪裡要設 I=5 I-- 阿~???
可否詳細的寫給我看一下~拜託~謝謝~!

jaming 2005-03-29 08:46 PM

原迴圈執行完接著再做一次迴圈...改成減的...
這是最笨的一個方法.... :flash:
提示完畢....

vanness70087 2005-03-29 09:29 PM

是在中間那段FOR裡面加嗎~?

doberman 2005-03-29 10:37 PM

裡面印"*"和換行的迴圈用
j=i;
while(condition){
statement;//印星星
j--;
}
statement;//換行

去寫好像會比較直觀,容易想通點...

doberman 2005-03-29 10:45 PM

然後意思跟jaming兄說的一樣,再做一次∼

小貓貓 2005-03-29 11:23 PM

For Demo
 
#include<iostream.h>

void main()
{
int x,y,z;
for(y=1; y<10; y++)
{
if ( y <= 4 )
{
for(x=1; x<=y; x++)
{
cout<< '*';
}
}
else
{
for(x=4; x>=(y-5) ; x--)
{
cout<< '*';
}
}
cout<<endl;
}
}

su1j6y9 2005-03-30 02:05 AM

#include<stdio.h>
void main()
{
cout<<"*"<<endl;
cout<<"**"<<endl;
cout<<"***"<<endl;
cout<<"****"<<endl;
cout<<"*****"<<endl;
cout<<"****"<<endl;
cout<<"***"<<endl;
cout<<"**"<<endl;
cout<<"*"<<endl;
}

這樣就好啦 :D
(一切從簡啦)

leonlin 2005-03-30 02:26 AM

引用:
作者su1j6y9
#include<stdio.h>
void main()
{
cout<<"*"<<endl;
cout<<"**"<<endl;
cout<<"***"<<endl;
cout<<"****"<<endl;
cout<<"*****"<<endl;
cout<<"****"<<endl;
cout<<"***"<<endl;
cout<<"**"<<endl;
cout<<"*"<<endl;
}

這樣就好啦 :D
(一切從簡啦)


如果我是教 CS 的老師或助教 這個答案大概會拿零分或頂多一點同情分
如果我是業界雇用經理 應該會錄取你(如果題目再簡化一點;比如只要印五行)... 有些時後真的是要務實一點....


所有的時間均為GMT +8。 現在的時間是12:35 PM.

vBulletin Version 3.0.1
powered_by_vbulletin 2024。