how can print this?with for loop?

Example input
Sample 1
3

Sample 2
7
Example output
Sample 1
a..a
a.ab
aabc

Sample 2
a......a
a.....ab
a....abc
a...abcd
a..abcde
a.abcdef
aabcdefg
Would you be able to print
1  1
1 12
1123
or
*  *
* **
****
or at least
*
**
***
?
no,unfortunately
Do you understand the basics of for loops though? For this, you would use nested for loops.
@tural: algotihm and learn loops
The key to drawing triangles like that is to notice how numbers of characters change on each line.
For example, in
*
**
***
triangle, you see that each line has one more * than the previous one.
So the algorithm would be
1
2
3
4
5
6
int number_of_stars = 1;
for (int i = 0; i < 3; i++) {
   draw_stars (number_of_stars);
   cout << '\n';
   number_of_stars ++;
}
where draw_stars (number_of_stars) is
1
2
for (int j = 0; j < number_of_stars; j++)
   cout << '*';
Notice that number_of_stars = i+1 in this case. No matter what the triangle is, they are closely related, so you really only need one of them.
Topic archived. No new replies allowed.