C
C#2y ago
Reki-

❔ Loop pyramid

how to write this one
13 Replies
Thinker
Thinker2y ago
You know what a for loop is?
Reki-
Reki-2y ago
yes but i dont know how to do this loop pyramid its hard for me can you write this loop code for me? just once
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
GameShark
GameShark2y ago
this should give you an idea on how to solve the problem: https://learn.microsoft.com/en-us/dotnet/standard/base-types/padding
Padding Strings in .NET
Learn how to pad strings in .NET. Use the String.PadLeft and String.PadRight methods to add leading or trailing characters to achieve a specified total length.
ero
ero2y ago
This has nothing to do with padding
Thinker
Thinker2y ago
Well, firstly you'll want to loop between 0 and 6. Then for every iteration, you'll have to loop between the current number and 0, then from 0 back to the current number.
ero
ero2y ago
What
MODiX
MODiX2y ago
Ero#1111
REPL Result: Success
int num = 6;
string output = "0";

for (int i = 1; i <= num; i++)
{
output = i + output + i;
}

Console.WriteLine(output);
int num = 6;
string output = "0";

for (int i = 1; i <= num; i++)
{
output = i + output + i;
}

Console.WriteLine(output);
Console Output
6543210123456
6543210123456
Compile: 644.885ms | Execution: 84.463ms | React with ❌ to remove this embed.
ero
ero2y ago
Or do the writelines in the loop i guess Nah don't do the spoonfeed thing I was trying to show why what you suggested is bogus
Thinker
Thinker2y ago
I mean, there's a lot of ways you could do this. That's a completely valid way, although I suspect it's probably not the "intended" one in this situation. Also you practically just wrote half the thing for them
Reki-
Reki-2y ago
Thank you everyone I will try
GameShark
GameShark2y ago
to center the output
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.