Q:

Write a program in C# Sharp to display the pattern like pyramid using an asterisk and each row contain an odd number of an asterisks

0

Write a program in C# Sharp to display the pattern like pyramid using an asterisk and each row contain an odd number of an asterisks

  *                                                                                                    
 ***                                                                                                   
*****

Sample Output:

Display the pattern like pyramid containing odd number of asterisks:                                                                                           
----------------------------------------------------------------------                                                                                               
Input number of rows for this pattern :10                                                                                                         
         *                                                                                               
        ***                                                                                        
       *****                                                                                 
      *******                                                                                          
     *********
    ***********                       
   *************                  
  ***************                
 *****************

All Answers

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

using System;  
public class Exercise20  
{  
    public static void Main()
{
   int i,j,n;
   
	Console.Write("\n\n");
    Console.Write("Display the pattern like pyramid containing odd number of asterisks:\n");
    Console.Write("----------------------------------------------------------------------");
    Console.Write("\n\n");   
   
   Console.Write("Input number of rows for this pattern :");
   n= Convert.ToInt32(Console.ReadLine());    
   for(i=0;i<n;i++)
   {
     for(j=1;j<=n-i;j++)
     Console.Write(" ");
     for(j=1;j<=2*i-1;j++)
       Console.Write("*");
     Console.Write("\n");
   }
 }
} 

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