+ 10
C++
#include <iostream> using namespace std; int main() { int i; for(i=1;i<=5;++i) { cout<<"\n"; for(int j=1;j<=i;++j) cout<<i; } return 0; } Pls can i know the working proccess to get the output Also can someone explain the program for me please
14 Answers
+ 10
#include <iostream>
using namespace std;
int main() {
int i;
for (i = 1; i <= 5; ++i) // set the total "number of digits in each row" (e.g. row1 one digit, row2 two digits, row3 three digits and so on)
{
for (int j = 1; j <= i; ++j) { // handles the "number of prints (column)" based upon the current value of i
cout << i; // prints out the value of i
}
cout << "\n"; // break the line upon completion of each row
}
return 0;
}
1
22
333
4444
55555
+ 6
Increase j by one. Basically, j gets incremented when the program flow reaches to the right curly brace as
for (int j = 1; j <= i; ++j) {
} // here, j gets incremented after each loop cycle
+ 6
n = 15 # size
for x in range(n//2,n + 1,+2):
for y in range(1,n - x,+2):
print(" ",end="")
for y in range(1,x + 1):
print("*",end="")
for y in range(1,n - x + 1):
print(" ",end="")
for y in range(1,x + 1):
print("*",end="")
print()
for x in range(n, 0,-1):
for y in range(x, n):
print(" ",end="")
for y in range(1,(x * 2)):
print("*",end="")
print()
print("heart")
+ 5
I think the output will be like this :
1
22
333
4444
55555
Explanation :
In First iteration a new line and 1 from j (checks j(1)<=i(1)) will be executed
In Second iteration a new line and 22 from j (checks j(1)<=i(2) ie., checks 2 times inside second loop until the condition (j<=i) becomes false) will be executed inside the second for loop
In Third iteration a new line and 333 from j (checks j(1)<=i(3) ie., checks 3 times inside second loop until the condition (j<=i) becomes false) will be executed inside the second for loop
In Fourth iteration a new line and 4444 from j (checks j(1)<=i(4) ie., checks 4 times inside second loop until the condition (j<=i) becomes false) will be executed inside the second for loop
In Fifth iteration a new line and 55555 from j (checks j(1)<=i(5) ie., checks 5 times inside second loop until the condition (j<=i) becomes false) will be executed inside the second for loop
After both the loops becomes false the execution of the program terminates
+ 5
Dhanush Adithya thankyou
+ 5
"j is the value of digits"
No, the number of digits for printing out. `j` in the inner loop is responsible for iterating till the current value of `i` and provides the correct number of cycles over the `cout << i;`. For example, if the i = 3 in the outer loop, it says to the inner loop "iterate from 1 to 3 over cout << 3", so, in this particular iteration, the output would be as
333
+ 5
What is the meaning of ++j
+ 4
C++ Soldier (Babak) okay
+ 3
C++ Soldier (Babak) thankyou
i have a doubt
now is:
i the total number of digits
and
j is the value of digits
+ 1
Its a patteren like this one
https://code.sololearn.com/c5J3XgmqyX92/?ref=app
+ 1
When i=1 (1)
When i=2 (22)
When i=3 (333)
.
.
.
.
.
0
Narayana minutes balance
- 1
Output is
1
22
333
4444
55555