locked
how to get some shape RRS feed

  • Question

  • User-1634604574 posted

    i want to get this shape by c# console

                4

            4    3

         4    3    2

      4   3   2   1

    i have some code like this

      int rows,i,j,k,l=1;
      
        rows=4;
        cout<<"Here your pyramid pattern\n";
        for(i=1; i<=rows; i++){
            for(j=1; j<=rows-i; j++){//iterates for print space
            cout<<" ";//print space
        }
        for(k=1; k<=i; k++){
           cout<<k; //print number
           cout<<" ";//print space among the numnbers
        }
        cout<<"\n";
        k=k-1;
        }
      
        return 0;

    but i want the result starts from 4 then decreased like my output

    Friday, June 12, 2020 8:56 PM

All replies

  • User303363814 posted

    Your code is C++.  This is a C# forum, your code won't compile in c#.

    Your code is for a console application.  This is a site about web technologies.

    Friday, June 12, 2020 11:48 PM
  • User-1634604574 posted

    now is c#

    int rows,i,j,k,l=1;
      
        rows=4;
        cout<<"Here your pyramid pattern\n";
        for(i=1; i<=rows; i++){
            for(j=1; j<=rows-i; j++){//iterates for print space
            console.writeline(" ");//print space
        }
        for(k=1; k<=i; k++){
           console.writeline(k);
            console.writeline(" ");
           
        }
         console.writeline("\n");
        k=k-1;
        }

    Saturday, June 13, 2020 5:37 AM
  • User-474980206 posted

    simple:

    using System;
    
    public class Program
    {
        public static void Main()
        {
    	var rows = 4;
    	for (var row = 0; row < rows; ++row)
    	{
    	    for (var i = 1; i < rows - row; ++i)
    		Console.Write(" ");
    	    for (var i = rows; i >= rows - row; --i)
    		Console.Write($"{i} ");
    	    Console.WriteLine();
    	}
        }
    }

    Saturday, June 13, 2020 11:31 PM
  • User-1151440187 posted

    using System.IO;
    using System;

    class Program
    {
         public static void Main()
         {
             int i=4;

             for (var k = 0; k < i; ++k)
             {
                 for (var j = 0; j+1< i - k; ++j)
                 Console.Write(" ");
                 for (var j = i; j >= i - k; --j)
                        Console.Write($"{j} ");
                  Console.WriteLine();
              }
            }

    }

    Friday, March 12, 2021 7:12 AM