How can print the following output on console using for loop?
1
121
12321
1234321
123454321
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.
Banketeshvar NarayanPosted Nov 13, 2015, 10:23 AM
use the below code it will give the exact result you need.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication59
{
class Program
{
static void Main(string[] args)
{
int numberoflayer = 6, Space, Number;
Console.WriteLine("Print paramid");
for (int i = 1; i <= numberoflayer; i++) // Total number of layer for pramid
{
for (Space = 1; Space <= (numberoflayer - i); Space++) // Loop For Space
Console.Write(" ");
for (Number = 1; Number <= i; Number++) //increase the value
Console.Write(Number);
for (Number = (i - 1); Number >= 1; Number--) //decrease the value
Console.Write(Number);
Console.WriteLine();
}
}
}
Please accept as answer if it helps you!!
Banketeshvar NarayanPosted Nov 13, 2015, 10:34 AM
Pisi CanPosted Nov 13, 2015, 10:30 AM
Banketeshvar NarayanPosted Nov 13, 2015, 9:27 AM
this link may help you
http://stackoverflow.com/questions/5037012/making-pyramid-using-c-sharp