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

  • برمجة سي شارب
  • برمجة

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

الأجوبة

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--;
  }
 }
} 
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...