15,902,931 members
See more:
hello,

i want to print string pyramid as : it should display first character from entered string in first line, 2 character from entered string in second line, 3 character from entered string in third line and so on.

for e.g. csharp

c
cs
csh
csha
cshar
csharp

Posted
Updated 27-Feb-13 21:59pm
v2

## Solution 1

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

But this really isn't difficult: all you need is two nested loops: one goes through the number of characters and prints a line each time. It contains another loop which prints the number of characters for that line number.

Seriously - try it. It's about four lines of code if you ignore brackets and comments!

## Solution 2

Solution for e.g. csharp

c
cs
csh
csha
cshar
csharp

Below is the code e.g above
--------------------------------------------------------------------------------------
for (int i = 0; i<=7; i++){

for (int j = 1; j <i;>
{
if (j == 1) { Console.Write("C"); }
if (j == 2) { Console.Write("S"); }
if (j == 3) { Console.Write("h"); }
if (j == 4) { Console.Write("a"); }
if (j == 5) { Console.Write("r"); }
if (j == 6) { Console.Write("p"); }
}

Console.WriteLine();

}

v2
Dave Kreskowiak 2-Jul-15 9:45am
Do NOT post answers to homework questions! You are only helping the person fail.

Matt T Heffron 2-Jul-15 13:05pm
Dave ... on a 2 year old question? ;-)
Dave Kreskowiak 2-Jul-15 15:30pm
Yeah, I keep missing the stupid date it was posted. F'in spammers are resurrecting old questions to post their sh*t.

## Solution 3

So easy just copy and paste this code...
C#
```using System;
namespace PiramidPrint
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter any string: ");
for (int i = 0; i < input.Length; i++)
{
for (int j = 0; j < i + 1; j++)
{
Console.Write(input[j]);
}
Console.WriteLine();
}

}
}
}```