I Have Facing problem to print number in triangle format in C# this is just like a print Star (*) in triangle
|1 \|2 6 \|3 7 10 \|4 8 11 13 \|5 9 12 14 15 \-------------------please suggest me how can i resolve this problem
thanks
I Have Facing problem to print number in triangle format in C# this is just like a print Star (*) in triangle
|1 \|2 6 \|3 7 10 \|4 8 11 13 \|5 9 12 14 15 \-------------------please suggest me how can i resolve this problem
thanks
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 Feb 22, 2015, 8:04 AM
n = int.Parse(Console.ReadLine());
int m=0,cr=0;
for (int a = 0; a < n; a++)
{
Console.Write("|");
for (int c = 0; c <= a; c++)
{
if (c == 0)
{ if(a<9)
Console.Write("{0} ", a + 1);
else
Console.Write("{0} ", a + 1);
m = a + 1;
}
else
{
m = n + m - c;
if (10<=m && m<90)
Console.Write("{0} ", m);
else if(m>=91&&m<100)
Console.Write("{0} ", m);
else
Console.Write("{0} ", m);
}
}
Console.Write("\\");
cr = Console.CursorLeft + 2;
Console.WriteLine();
}
Console.WriteLine(new string('-',cr));
Console.ReadKey();
}
VulpesPosted Feb 21, 2015, 4:02 PM