How can we print the following given pattern?
123454321
1234 4321
123 321
12 21
1 1
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 29, 2015, 8:10 PM EDT
The first value is static.Then you can directly replace the value..
Eg :
string str_value = "123454321": // direct value..
Foreach (var str in str_value)
{
str.Replace("5"," ");//output 1234 4321
str.Replace("4"," "); // 123 321
}
Try the above or search otherformat also..
This answer is helpful.Then please accept..
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Aug 30, 2015, 2:05 AM EDT
Console.WriteLine("Wnter Your Number");
n = int.Parse(Console.ReadLine());
for (i = 1; i <= n; i++)
Console.Write(i.ToString());
for (j = i - 2; j >= 1;j-- )
Console.Write(j.ToString());
Console.WriteLine();
for (i = 1; i <= n-1; i++)
{
for (j = 1; j <= n - i; j++)
Console.Write(j.ToString());
for (j = 1; j < 2 * i ; j++)
Console.Write(" ");
for (j = n - i; j >= 1; j--)
Console.Write(j.ToString());
Console.WriteLine();
}
Console.ReadKey();