Skip to main content
Post Deleted by CommunityBot
edited tags
Link
Cody Gray
  • 246.2k
  • 53
  • 514
  • 591
Post Locked by CommunityBot
Post Migrated Away to codereview.stackexchange.com by Cody Gray
Post Closed as "Not suitable for this site" by Cody Gray
Post Reopened by Cody Gray
added 30 characters in body; edited title
Source Link
Cody Gray
  • 246.2k
  • 53
  • 514
  • 591

Pyramid Program C# program that prints an ASCII pyramid

Below is the screenshot of the code in which I have made a pyramidwritten the following program. My question is in C# to display an ASCII pyramid. Is it a good code from the performance point of view or not?

public static void method1()
{
  int k;
  int kCond = 5;
  int i;
  int inc = 0;
  for (int p = 0; p <=5; p++)
  {
    for(k = 0; k <= kCond; k++)
    {
         Console.Write(" ");
    }
     kCond--;
     for(i=0; i<=inc; i++)
     {
        Console.Write("*")
     }
     inc +=2;
     Console.WriteLine();
  }
}
 

Output:

         *
        ***
       *****
      *******
     *********
    ***********

My question is, is this good code from a performance point of view, or not? How could I improve it?

Pyramid Program C#

Below is the screenshot of the code in which I have made a pyramid program. My question is. Is it a good code from the performance point of view or not?

public static void method1()
{
  int k;
  int kCond = 5;
  int i;
  int inc = 0;
  for (int p = 0; p <=5; p++)
  {
    for(k = 0; k <= kCond; k++)
    {
         Console.Write(" ");
    }
     kCond--;
     for(i=0; i<=inc; i++)
     {
        Console.Write("*")
     }
     inc +=2;
     Console.WriteLine();
  }
}
 
         *
        ***
       *****
      *******
     *********
    ***********

C# program that prints an ASCII pyramid

I have written the following program in C# to display an ASCII pyramid.

public static void method1()
{
  int k;
  int kCond = 5;
  int i;
  int inc = 0;
  for (int p = 0; p <=5; p++)
  {
    for(k = 0; k <= kCond; k++)
    {
         Console.Write(" ");
    }
     kCond--;
     for(i=0; i<=inc; i++)
     {
        Console.Write("*")
     }
     inc +=2;
     Console.WriteLine();
  }
}

Output:

         *
        ***
       *****
      *******
     *********
    ***********

My question is, is this good code from a performance point of view, or not? How could I improve it?

Post Closed as "Opinion-based" by GSerg, Rubens Farias, burning_LEGION, LarsTech, Camilo Terevinto
edited title
Link
Andrew
  • 20.4k
  • 13
  • 111
  • 122

Pyramid PorgramProgram C#

Source Link
Loading