How to find the factorial of a number using c#

There are two approaches you can try for the above scenario one is with recursion and another one is using for loop.



        

  static void Main(string[] args)
        {
           int rslt= FactorialWithoutR(5);
           Console.WriteLine("Factorial is :{0}", rslt);
        }

        public static int Factorial(int limit)
        {
            // Using Recursion
            if (limit == 0)
            {
                return 1;
            }
            return limit * Factorial(limit - 1);
        }

        public static int FactorialWithoutR(int limit)
        {

            int factorial = 1;
            for (int i = 1; i <= limit; i++)
            {
                factorial = factorial * i;
            }
            return factorial;
        }

How to create Fibonacci series for the given limit using C#

Please find the solution for the same below.




















        

  static void Main(string[] args)
        {
            Fibonacci(10);
        }

        public static void Fibonacci(int limit)
        {
            // Method 1
            int a = 0; int b = 1; int c=0;
            Console.WriteLine("Method 1");
            Console.WriteLine("Fib Series : {0},{1}", a, b);
            for(int i = 2; i < limit; i++)
            {
                c = a + b;
                Console.Write("{0} ",c);
                a = b;
                b = c;

            }

            // Method 2
            int[] fibnArray = new int[limit];
            fibnArray[0] = 0;
            fibnArray[1] = 1;

            for (int i = 2; i < limit; i++)
            {
                fibnArray[i] = fibnArray[i - 2] + fibnArray[i - 1];
            }

            string fib1 = "";
            fibnArray.ToList().ForEach(x => { fib1 = fib1 + x.ToString() + ","; });
            Console.WriteLine("\n Method 2");
            Console.WriteLine("Fibonacci Series " + fib1);

            //Method 3
            Console.WriteLine("Method 3");
            Recurring(0, 1, 1, 10);
            // Method 4
            List fibnList = new List();
            for (int i = 0; i < limit; i++)
            {
                if (i == 0 || i == 1)
                {
                    fibnList.Add(i);
                }
                else
                {
                    fibnList.Add(fibnList[i - 2] + fibnList[i-1]);
                }

            }
            string fib = "";
            fibnList.ForEach(x => { fib = fib + x.ToString() + ","; });
            Console.WriteLine("\n Method 4");
            Console.WriteLine("Fibonacci Series " + fib);
            Console.ReadLine();
        }

        public static void Recurring(int a,int b,int counter,int limit)
        {
            if (counter < limit)
            {
                Console.Write(a);
                int c = a + b;
                counter = counter + 1;
                Recurring(b, c,counter , limit);
            }
                    
        }

how to convert uppercase to lowercase and lowercase to uppercase of given string using c#

Here I am solving the problem using C# programming language


        

   static class Program
    {
        static void Main(string[] args)
        {
            CaseConvertion("Coder Juggernaut Blog");
        }

        public static void CaseConvertion(string input)
        {

            string newString = "";
            foreach (char item in input)
            {
                if (char.IsLower(item))
                {
                    string upper = item.ToString().ToUpper();
                    newString = newString + upper;

                }
                else if (char.IsUpper(item))
                {
                    string lower =  item.ToString().ToLower();
                    newString = newString + lower;
                }
                else
                {
                    newString = newString + " ";
                }
               
            }

            Console.WriteLine("Conerted  Name : {0} ", newString);
            Console.ReadLine();
        }
    }

How to find the count of numbers,letters and special character from the given string C#

This is a common interview question. here I am going to solve it using C# programming language.

 




       

 static class Program
    {
        static void Main(string[] args)
        {
            FindCount("abc2D$%@");
        }

        public static void FindCount(string input)
        {
            int num_count = 0;
            int letter_count = 0;
            int symbol_Cont = 0;

            foreach (char item in input)
            {
                if (char.IsNumber(item))
                {
                    num_count = num_count + 1;

                }
                else if (char.IsLetter(item))
                {
                    letter_count++;
                }
                else
                {
                    symbol_Cont++;
                }
            }

            Console.WriteLine("Num Count: {0},letter Count: {1} symbol Count: {2} ",
             num_count, letter_count, symbol_Cont);
            Console.ReadLine();
        }
    }