how to print numbers like this

Posted by Johnseelan under C# on 7/28/2011 | Points: 10 | Views : 2083 | Status : [Member] | Replies : 2
if i am passing 2 as a input i need to print numbers like below
1
3 2

if i am passing 3 as a input i need to print numbers like below
1
3 2
6 5 4

if i am passing 4 as a input i need to print numbers like below
1
3 2
6 5 4
10 9 8 7

please any one give correct logic in C#




Responses

Posted by: Hiren009 on: 7/28/2011 [Member] Starter | Points: 25

Up
0
Down
Hey @Johnseelan, try below code

class Program

{
static void Main(string[] args)
{
Console.Write("Enter Number : ");
int IntInput = 0 ;
try
{
IntInput = Convert.ToInt32(Console.ReadLine());

int intCnt = 1;
for (int i = 1; i <= IntInput; i++)
{
intCnt += i;
for (int j = 1; j <= i; j++)
{
Console.Write("{0} ", intCnt - j);
}

Console.WriteLine();
}


}
catch (Exception)
{
Console.WriteLine("Please Enter Valid Number");
}

}
}

 Download source file

Cheers,
Hiren Patel

Johnseelan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Johnseelan on: 7/28/2011 [Member] Starter | Points: 25

Up
0
Down
Thanks Hiran....


Johnseelan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response