samedi 18 janvier 2020

Better way to solve this pattern ? 1*2*3*4*17*18*19*20

class Program {enter code here static void Main() { int blank = 0, value = 0,temp = 1,temp2 =0; Console.WriteLine("Enter Total Row Number"); int n = Convert.ToInt3enter code here2(Console.ReadLine()); value = n; temp2 = n * (n+1); while (n >= 1) { for (int i = 0; i < value-n; i++) { Console.Write(" "); } for (int i = temp; i < temp+n; i++) { Console.Write(i + "*"); } temp = temp+n; temp2 = temp2 - n; for (int i = temp2 +1; i <= temp2 + n; i++) { Console.Write(i); if(i != n * (n + 1)) Console.Write("*"); }

            n -= 1;
            Console.WriteLine();                
        }

        Console.ReadKey();
    }
}

Aucun commentaire:

Enregistrer un commentaire