Output:-
1
1,2
1,2,3
1,2,3,4
1,2,3,4,5
enter user input to print program n length
If i put 5 then program run the length of 5 time.
Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Program
{
class Program
{
static void Main(string[] args)
{
int length= Convert.ToInt32(Console.ReadLine()); //enter user input
Console.Write(Environment.NewLine); //new line
for (int i = 0; i < length; i++)
{
string printValues = string.Empty;
for (int j = 1; j <= i+1; j++)
{
printValues = printValues + j +",";
if(i+1 == j)
{
if (printValues.Contains(","))
{
printValues = printValues.Remove(printValues.Length - 1, 1);
}
Console.WriteLine(printValues);
}
}
}
Console.ReadLine();
}
}
}
1
1,2
1,2,3
1,2,3,4
1,2,3,4,5
enter user input to print program n length
If i put 5 then program run the length of 5 time.
Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Program
{
class Program
{
static void Main(string[] args)
{
int length= Convert.ToInt32(Console.ReadLine()); //enter user input
Console.Write(Environment.NewLine); //new line
for (int i = 0; i < length; i++)
{
string printValues = string.Empty;
for (int j = 1; j <= i+1; j++)
{
printValues = printValues + j +",";
if(i+1 == j)
{
if (printValues.Contains(","))
{
printValues = printValues.Remove(printValues.Length - 1, 1);
}
Console.WriteLine(printValues);
}
}
}
Console.ReadLine();
}
}
}
No comments:
Post a Comment