Use nested loop to print the following patterns.In java or C++
1
21
321
4321
54321
12345
1234
123
12
1
Please help me to get the Java/C++ coding to display patterns below?
Maybe something like this?
I haven't tested and it's been ages since I used c++ so the syntax may not be correct.
string temp1 = "";
string temp2 = "";
for(int i = 1 ; i%26lt;6 ; i++) {
cout %26lt;%26lt; i + temp2;
temp2 = i + temp1;
temp1 = temp2;
}
temp1 = "";
temp2 = "";
for(int x = 1 ; x%26lt;6 ; x++) {
for(int y = 1 ; y%26lt;(7-x) ; y++) {
temp2 = temp1 + i;
temp1 = temp2;
}
cout %26lt;%26lt; temp2;
temp1 = "";
temp2 = "";
}
Reply:i 'll jus show the loops
1
21
321
4321
54321
for(j=1;j%26lt;=5;j++)
{
for(i=5;i%26gt;=1;i--)
{
if (i%26lt;=j)
cout%26lt;%26lt;i;
}
cout%26lt;%26lt;endl;
}
12345
1234
123
12
1
for(j=5;j%26gt;=1;j--)
{
for(i=1;i%26lt;=j;i++)
{
cout%26lt;%26lt;i;
}
cout%26lt;%26lt;endl;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment