Assume that the int variables i and j have been declared, and that n has been declared and initialized. using for loops (you may need more than one), write code that will cause a triangle of asterisks of size n to be output to the screen.

Respuesta :

You should really state what language you're using. Here it is easily produced in C#, and shouldn't be too much of a hassle to translate to other languages. Note that I did not need to use the iterative variable ( j ), and could instead just use ( i ) in one for loop.

Console.Write("Enter size of triangle: ");           
int n = Convert.ToInt32(Console.ReadLine());         
for (int i = n - 1; i >= 0; i--)               
    Console.WriteLine(new String('*', n - i));