+ 1
How to print this method
1***** 12**** 123*** 1234** 12345*
4 Answers
+ 19
1)run an outer loop from n=1 to n=n
2)inner loop 1 : for int a=1;a <=n;a++ ... print a
3)inner loop 3 : for int b=6-n; while (b--!=0) print "*"
4)then jump to nextline using "\n"
+ 4
In C++
#include <string>
#include <iostream>
int main()
{
std::string txt(6, 42);
for(unsigned int i = 0; i < 5; i++)
{
txt[i] = char(i + 49);
std::cout << txt << "\n";
}
return 0;
}
By the way, if this was a challenge, why not submit this as an assignment in Lesson Factory, there goes most challenges nowadays : )
+ 1
outer_loop: 1-5
inner_loop: 1-outer_loop and 6 minus outer_loop for "*"
Python3:
for i in range(1,6):
for j in range(1,i+1):
print(j, end='', sep='')
for j in range(6-i):
print('*', end='')
print('')
0
talk is cheap show me the code!!