我有写c ++程序的问题 [英] I have proplem writting C++ program

查看:129
本文介绍了我有写c ++程序的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用for循环编写C ++程序,输出以下模式。程序应该提示用户输入整数。

提示 - 使用功能。

示例1:如果用户输入7,则输出应为:



Write a C++ program using for loop that outputs the following pattern. The program should prompt the user for an integer number.
Hint – Use a function.
Example 1: if the user enters 7, then the output should be:

1
22
333
4444
55555
666666
7777777





示例2:如果用户输入3,则输出应为:





Example 2: if the user enters 3, then the output should be:

1
22
333





我的尝试:





What I have tried:

#include <iostream>

using namespace std;

int main()
{ int lineNo;
int x;
int num;
cout<<"enter a number "<<endl;
cin>>num;
for (lineNo = 1; lineNo <= num ; lineNo ++)
    {
        for (x = 1; x <= lineNo  ; x++)
                  cout<<num;
    cout<<endl;
    }
    return 0;
}

推荐答案

Quote:

我试图这样做但它永远不适合我

I tried to do it but it never works for me

我们知道它不适合你,否则你不会在这里。

显示你的代码并解释你的问题,显示实际结果也是一个信息。

[更新]

尝试更换

We know it didn't work for you because otherwise you wouldn't be here.
Show your code and explain your problem, showing actual result is also an information.
[Update]
Try to replace

cout<<num;



with


with

cout<<lineNo;



你写的是行数而不是当前的行号。

[结束更新]



我们不是做你的家庭工作。

HomeWork不会在乞求别人做你的工作时测试你的技能,它会让你思考并帮助你的老师检查你对你所拥有的课程的理解采取以及你应用它们时遇到的问题。

你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。

所以,试一试,重读你的课程并开始工作。如果您遇到特定问题,请显示您的代码并解释这个问题,我们可能会提供帮助。



作为程序员,您的工作是创建算法解决特定问题,你不能依赖别人永远为你做,所以有一段时间你必须学会​​如何。而且越快越好。

当你要求解决方案时,就像试图通过培训其他人来学习开车一样。

创建算法基本上是找到数学并做出必要的调整以适应你的实际问题。



建议:拿一张纸并尝试手工完成,你的程序应该使用相同的程序。


You were writing the number of lines instead of the current line number.
[End Update]

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.

Advice: take a sheet of paper and try to do it by hand, your program should use the same procedure.


这篇关于我有写c ++程序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆