C
C#3y ago
Reki-

❔ Loop pyramid

how to write this one
13 Replies
Thinker
Thinker3y ago
You know what a for loop is?
Reki-
Reki-OP3y 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 User3y ago
Message Not Public
Sign In & Join Server To View
GameShark
GameShark3y 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
ero3y ago
This has nothing to do with padding
Thinker
Thinker3y 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
ero3y ago
What
MODiX
MODiX3y 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
ero3y 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
Thinker3y 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-OP3y ago
Thank you everyone I will try
GameShark
GameShark3y ago
to center the output
Accord
Accord3y 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.
Want results from more Discord servers?
Add your server