Posts

Showing posts from August, 2018

Print pyramid shape by numbers between 1 to 9 in C#

Hello friends, try below code for printing Pyramid shape by any numbers between 1 to 9. E.g. If number=4, print pyramid shape as below:            1         21        321     4321      public class Program     {         static void Main(string[] args)         {             Console.Write("Enter any number between 1 to 9 : ");             int num = Convert.ToInt32(Console.ReadLine());             for (int i = 1; i <= num; i++)             {                 //printing space                 for (int j = i; j <= num - 1; j++)                     Console.Write(" ");                     int s = i;                     for (int k = 0; k < i; k++)                     {                         //printing numbers                         Console.Write(s--);                     }                     Console.WriteLine();               }             Console.ReadLine();         } Please leave your comments.