Answer to Question #243454 in C# for Gayatri

Question #243454

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


1
Expert's answer
2021-09-30T00:56:58-0400
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");
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS