Skip to main content

Beginner's Code for Diamond Pattern

using System;

public class Test
{
      public static void Main()
      {
            var n = Console.ReadLine();
            int no = Convert.ToInt32(n);
            Pattern print = new Pattern();
            print.Diamond(no);
      }
}
public class Pattern
{
      public void Diamond(int n)
      {
            int m = n*2;
           
            int dummy=n;
            for(int i=0;i<=m;i++)
            {
                  if(i<n)
                  {
                        dummy --;
                  }
                  else
                  {
                        if(i==n)
                        {
                              dummy=dummy;
                        }
                        else
                        {
                        dummy++;
                        }
                  }
                  for(int j=0;j<n;j++)
                  {
                        if(j<dummy)
                        {
                              Console.Write(" ");
                        }
                        else
                        {
                              Console.Write("* ");
                        }
                  }
                  Console.WriteLine();
            }
      }
}
3



 stdout

Please Enter n:3
*
* *
* * *
* * *
* *
*

Comments

Popular posts from this blog

BEGINNER's ALPHABET PALINDROME

PRINT ALPHABET PALINDROMIC PYRAMID USING C# using System; public class Test {       public static void Main()       {             var number = Console.ReadLine();             int n = Convert.ToInt32(number);             Pattern print = new Pattern();             print.PrintPalindromePattern(n);       } } public class Pattern {       public void PrintPalindromePattern(int n)       {             int dummy = 1;             char letter = 'A';             int reversep...

MINIMUM DISTANCE BETWEEN TWO SIMILAR STRINGS

LATEST using System ; using System . Linq ; public class Test { public static void Main () { int arrayLength ; int T = Convert . ToInt32 ( Console . ReadLine ()); for ( int i = 0 ; i < T ; i ++) { arrayLength = Convert . ToInt32 ( Console . ReadLine ()); string Line = Console . ReadLine (); GetMinimumDistanceBetweenStrings ( arrayLength , Line ); } } public static void GetMinimumDistanceBetweenStrings ( int length , string Line ) { int min = - 1 ; int initial = 0 ; string [] stringArray = Line . Split ( " " ); for ( int start = 0 ; start < length - 1 ; start ++) { for ( int a = start + 1 ; a <= length - 1 ; a ++) { if ( stringArray [ start ]== stringArray [ a ]) { if ( initial == 0 ) ...

GRANDSON PROBLEM

https://www.geeksforgeeks.org/zoho-interview-set-1-campus/ Given a two dimensional array of string like <”luke”, “shaw”> <”wayne”, “rooney”> <”rooney”, “ronaldo”> <”shaw”, “rooney”> Where the first string is “child”, second string is “Father”. And given “ronaldo” we have to find his no of grandchildren Here “ronaldo” has 2 grandchildren. So our output should be 2. SOLUTION using System; public class Test { public static void Main() { var noOfInputs = Console.ReadLine(); int noOfInputLines = Convert.ToInt32(noOfInputs); string[,] FatherSonArray= new String[noOfInputLines,noOfInputLines]; for(int father=0;father<noOfInputLines;father++) { for(int son=0;son<2;son++) { FatherSonArray[father,son] = Console.ReadLine(); } }     Console.WriteLine("No of grandchildrens:");     string GrandFather = Console.ReadLine();     int NoOfGrandSons=0;     Console.Wr...