2. Write a C# Sharp program that takes a number and a width also a number, as input and then displays a triangle of that width, using that number.
Test Data
Enter a number: 6
Enter the desired width: 6
Expected Output :
666666
66666
6666
666
66
6
using System;
namespace ConsoleApplication1
{
internal class Program
{
public static void Main(string[] args)
{
Console.Write("Enter a number: ");
var number = Console.ReadLine();
Console.Write("Enter the desired width: ");
var width = int.Parse(Console.ReadLine());
for (var i = width; i > 0; i--)
{
for (var j = 0; j < i; j++)
{
Console.Write(number);
}
Console.Write("\n");
}
}
}
}
Comments
Leave a comment