Showing posts with label Data Structures and Algorithms. Show all posts
Showing posts with label Data Structures and Algorithms. Show all posts

Datastructures and Algorithms in C#

Datastructures and Algorithms in C#

 

Datastructures and Algorithms in C# 


  1. C# Programming Questions on Strings
  2. C# Programming Questions on  Numbers in C#
  3. C# Programming Questions on Arrays in C#
  4. C# Programming Questions on Datastructures
  5. Sorting Algorithms And other Algorithms in C#

----------------------------------------------------------------------------------------------

Finding sum of digits of a number until sum becomes single digit in C#

 

Finding sum of digits of a number until sum becomes single digit in C#

Find the Number Occurring Odd Number of Times in C#

 

Find the Number Occurring Odd Number of Times in C#


C# Code

        static void getOddOccurrence()

        {

            int[] arr = { 2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2 };

            int length = arr.Length;

 

            for (int i = 0; i < length; i++)

            {

                int count = 0;

 

                for (int j = 0; j < length; j++)

                {

                    if (arr[i] == arr[j])

                        count++;

                }

                if (count % 2 != 0)

                {

                    Console.WriteLine("Odd Occurrence number is :- " + arr[i]);

                    return;

                }

            }

            Console.WriteLine(-1);

        }

output


Logic 2:-

    static void getOddOccurrence()

        {

            int[] arr = { 2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2 };

            int length = arr.Length;

            int res = 0;

            for (int i = 0; i < length; i++)

            {

                res = res ^ arr[i];

            }

         Console.WriteLine("Odd Occurrence number is :-  " +  res);

        }