查看: 849|回复: 5
|
C++问题....麻烦了!
[复制链接]
|
|
小弟有题问题不会,麻烦各位大大看看!
Enter the number of star lines (1 to 20) to be printed : 21
Number of star lines should be between 1 and 20
Enter the number of star lines (1 to 20) to be printed : -5
Number of star lines should be between 1 and 20
Enter the number of star lines (1 to 20) to be printed : 8
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
press any key to continue... |
|
|
|
|
|
|
|
楼主 |
发表于 13-4-2006 09:09 PM
|
显示全部楼层
我的coding是这样
#include <iostream>
using namespace std;
int main()
{
int row, i, j=1, k, t;
cout<<"Input row: ";
cin>>row;
for(i=((row+1)/2);i>0;i--)
{
for(t=0;t<i; t++)
cout<<" ";
for(k=0;k<j;k++)
cout<<"* ";
cout<<endl;
j++;
}
system("pause");
return 0;
} |
|
|
|
|
|
|
|
楼主 |
发表于 13-4-2006 09:09 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 14-4-2006 07:40 AM
|
显示全部楼层
我沒試過的。其它的自己做。
void PrintLine(int Lines)
{
int line, i;
for (line = 0; line < Lines; line++)
{
for (i = line; i < 30; i++) cout << " ";
for (i = -1; i < line; i++) cout << "* ";
cout << endl;
}
} |
|
|
|
|
|
|
|
发表于 14-4-2006 09:06 AM
|
显示全部楼层
void displayLine(int iLines){
int i,j;
for(i=0;i<iLines;i++){
for(j=0;j<iLines-i-1;j++){
printf(" ");
}
for(j=0;j<i+1;j++){
if(i==0)
printf("*");
else{
printf("*");
printf(" ");
}
}
printf("\n");
}
}
应该是这样作。。。, 以compile过。。。
[ 本帖最后由 asimo 于 15-4-2006 09:02 AM 编辑 ] |
|
|
|
|
|
|
|
发表于 14-4-2006 07:52 PM
|
显示全部楼层
原帖由 vwyk 于 13-4-2006 09:08 PM 发表
小弟有题问题不会,麻烦各位大大看看!
Enter the number of star lines (1 to 20) to be printed : 21
Number of star lines should be between 1 and 20
Enter the number of star lines (1 to 20) to be ...
this enforce that you need to do some error checking....
which number suppose in between 1-20.
原帖由 vwyk 于 13-4-2006 09:08 PM 发表
小弟有题问题不会,麻烦各位大大看看!
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
for this part.....
first need to determine how many line of star is needed,which is input number. to print the first star....use loop to print the space first which is half of the input number. the continues -1 for the space.
after the space..just print out the star.....complete.... |
|
|
|
|
|
|
| |
本周最热论坛帖子
|