Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 394
  • Last Modified:

Needs help in logic

Hi guys: Can any one please help me how to i print the * in that order that first it print one then two and then three. I try it first but made mistakes as its printing three in each row

Output required
*
**
***

#include <iostream>
using namespace std;

int main()
{
      for (int row = 1; row < 4; row +=1)
      {
            for(int asterisks = 1; asterisks <= 3; asterisks +=1)
                  cout << '*';
      cout << endl;
      }
      system("pause");
      return 0;
}
0
mustish1
Asked:
mustish1
  • 3
  • 2
2 Solutions
 
TommySzalapskiCommented:
change asterisks <= 3 to asterisks <= row
0
 
mustish1Author Commented:
Thanks. just last thing how to i reverse it means
***
**
*
0
 
TommySzalapskiCommented:
replace asterisks <= row with asterisks <= (4-row)
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
TommySzalapskiCommented:
See how that works? As row gets higher, now the max value gets lower.
0
 
phoffricCommented:
It may be a little less confusing if you define a function, print_row_of_asterisks(int numberOfAsterisks), and just call that function in a single loop. The loop inside the function should then be easy to figure out.

Also, the code will look a lot cleaner.
0
 
mustish1Author Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now