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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj Kumar ChoudharyPosted Aug 30, 2015, 6:05 AM
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();
Rajeesh MenothPosted Aug 30, 2015, 12:10 AM
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..