佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 792|回复: 5

C++问题....麻烦了!

[复制链接]
发表于 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 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...
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 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....
回复

使用道具 举报

Follow Us
您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 26-4-2024 07:12 PM , Processed in 0.063968 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表