Q:

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

0

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

Sample Output:

Input a number: 2                                                                                             
Input the desired width: 5                                                                                    
22222
2222
222
22  
2

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
public class Exercise2
{
  public static void Main()
  {
   Console.Write("Input a number: ");
   int num = Convert.ToInt32( Console.ReadLine() );
 
   Console.Write("Input the desired width: ");
   int width = Convert.ToInt32( Console.ReadLine() );
 
   int height = width;   
   for (int row=0; row < height; row++)
   {
    for (int column=0; column < width; column++)
   {
   Console.Write( num );
  }
 
   Console.WriteLine();
   width--;
  }
 }
} 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now