Skip to main content

Posts

Showing posts from November, 2019

CHARACTER OR VOWEL

LATEST using System; public class Test { public static void Main() {       var Letter = Console.ReadLine();       char c = char.Parse(Letter);       if(CheckIfCharacterisVowel(c))       {          Console.WriteLine("YES");       }       else       {       Console.WriteLine("NO");       } } public static bool CheckIfCharacterisVowel(char c) { if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U'|| c=='a'||c=='e'||c=='i'||c=='o'||c=='u') { return true; } return false; } }

NQUEEN's PROBLEM

using System; public class GFG { static int n; static public void Main () { var TC = Console.ReadLine(); int T = Convert.ToInt32(TC); for(int a=0;a<T;a++) {     var no= Console.ReadLine();      n = Convert.ToInt32(no);     int [,]board =  new int [n,n];     InitializeBoardWithZeros(board,n,n);     SolveNQueen(board,0);     PrintBoard(board,n,n); } } static public void InitializeBoardWithZeros(int [,]board,int row,int col) {     for(int i=0;i<col;i++)     {         for(int j=0;j<row;j++)         {             board[i,j]=0;         }     }     } static public void PrintBoard(int [,]board,int row,int col) { for(int i=0;i<col;i++)     {         for(int j=0;j<row;j++) ...

BEGINNER's Palindromic pattern with number and stars

PRINT A PALINDROME WITH NUMBERS AND STARS APPROACH The same flag can be set to 0 and 1 simultaneously to print * and the Ith iteration number continuously inside the triangle. The same logic used in the previous problem is used here to create a triangle pattern. SOLUTION : using System; public class Test {           public static void Main()           {                    var number = Console.ReadLine();                    int n = Convert.ToInt32(number);                    Pattern print = new Pattern();                  ...

BEGINNER's TRICKY NUMBER FULL PYRAMID

                             PRINT A NUMBER PYRAMID AS MENTIONED BELOW : APPROACH The whole pyramid structure can be written in a single nested for loop instead of many separate loops A single nested for loop is used along with two flags that help in creating the pyramid structure.One flag moves towards left by 1 and the other to the right by 1. If the iteration is at the boundary of the triangle ( leftTriangleCreater, rightTriangleCreater)  , those can print the Ith Iteration value While loop can be used to control the values on the left and right. In the left , The while loop iterates till secondelement != middleNumber In the right, The while loop iterates till rightsecondElement > i SOLUTION using System; public class Test { public static void Main() {   var number = Console.ReadLine();   int n = Convert.ToInt32(number);   Pattern print = ne...

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...

BEGINNER's PALINDROMIC NUMBER PYRAMID

LATEST PRINT A PALINDROME NUMBER PYRAMID AS SHOWN BELOW 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;             int reversepalindrome;         ...

BEGINNER's FULL NUMBER PYRAMID

using System; public class Test { public static void Main() { var no = Console.ReadLine(); int n = Convert.ToInt32(no); Pattern print = new Pattern(); print.Pyramid(n); } } public class Pattern { public  void Pyramid(int n) { int m = n*2; int left = n; int right = n; int dummy=1; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(j<left || j>right) { Console.Write(" "); } else { if(j==left && i!=n) { Console.Write("1"); } else if(j==right && i!=n) { Console.Write(i); } else if(i==n && dummy<=n) { Console.Write("{0} ",dummy); dummy++; } else { Console.Write(" "); } } } left--; right++; Console.WriteLine(); } } } INPUT : 5 OUTPUT: 1 1 2 1 3 1 4 1 2 3 4 5