program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class Class3
{
static void Main(string[] args)
{
int i, j, x;
Console.WriteLine("Enter value of x:");
x = int.Parse(Console.ReadLine());
for (i = 1; i <= x; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write(" "+j);
}
Console.WriteLine();
}
Console.WriteLine();
for (i = x; i >= 1; i--)
{
for (j = i; j >= 1; j--)
{
Console.Write(" " + j);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
Explanation: The First two For loops are used to display the first five lines of the output. The next two For loops are used to display the last five lines of the output. The outputs of the first five lines are in ascending order whereas the last five lines of the numbers are in the descending order.
Output :
Enter value of x : 5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class Class3
{
static void Main(string[] args)
{
int i, j, x;
Console.WriteLine("Enter value of x:");
x = int.Parse(Console.ReadLine());
for (i = 1; i <= x; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write(" "+j);
}
Console.WriteLine();
}
Console.WriteLine();
for (i = x; i >= 1; i--)
{
for (j = i; j >= 1; j--)
{
Console.Write(" " + j);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
Explanation: The First two For loops are used to display the first five lines of the output. The next two For loops are used to display the last five lines of the output. The outputs of the first five lines are in ascending order whereas the last five lines of the numbers are in the descending order.
Output :
Enter value of x : 5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
1
ReplyDelete2 3
4 5 6
7 8 9 10.
i need this output in c#.net console app.
can any one please help me