C# Logical Interview Questions And Answers

C# Logical Interview Questions And Answers

 

Below are the most commonly asked logical question in interviews for freshers and experience. you can find the questions like swapping the numbers, palindrome, Armstrong number, sum of the given numbers, swap the two numbers in the given array, etc.

  Before going to Top interview question and answers. I am going to give some tricks to crack the logical interview question.

      1.  Modules -->%  it gives the remainder and
      2. By --> / it gives the  coefficient

example :

 no=6789;

  • no%10 = it gives a reminder that means units place number
  • no%10 is used to identify the units place number
  • no/10 is used to delete the units places number

Below are the top interview question on integer and string arrays.

Integer Array Example Questions :

  1. Find the sum of the given individual numbers
  2. Find the sum of the Squares of the given individual numbers
  3. Find the sum of the Cubes of the given individual numbers
  4. Reverse the given Number
  5. Check the given number is Palindrome Number or not
  6. Check the Given Number is Armstrong or not
  7. Simple Array iteration of the integer Array
  8. Sum of the given Integer Array
  9. Simple Array iteration using read the size and entering the custom values
  10. Finding the Largest Number in the given Array Integer
  11. Finding the least Number in the given Array Integer
  12. Swap two numbers without using the third variable
  13. Swap the twp numbers using third variables
  14. Find the sum of even numbers and odd numbers in the given Array
  15. Find the count of even numbers and odd numbers in the given Array
  16. Find the First Largest Number and Second Largest Number in the Given Array
  17. Find the First Lowest Number and Second Lowest Number in the Given Array
  18. Program to swap the Minimum Value and Maximum Value in the given Array

String Arrays Example Questions :

  1. Reverse the given String
  2. check given string is palindrome or not
  3. write a program for replacing the "," with " "spaces
  4. write a program to replace the "," with "?" spaces
  5. write a program to count the number of Vowels and Consonants in the given array
  6. write the program to print the only Vowels count and Consonants count(remove duplicates)
  7. write the program from Lowercase to Uppercase
  8. write the program from Uppercase to Lowercase 
  9. reverse the words in the given string

Find the sum of the given individual numbers


using System;

using System.Collections.Generic;

namespace ConsolePractice

{

    class Program

    {

        static void Main(string[] args)

        {

            int no = 7890;

            int r = 0;

            int sum = 0;

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

            {

                r = no % 10; // moduler is used to identitify the units place

                sum = sum + r;

                no = no / 10; // by is used to delete the units place

            }

            Console.WriteLine("sum of the given digits" + sum);

            Console.ReadLine();

        }

    }

}



Find the sum of the Squares of the given individual numbers &
 Find the sum of the cubes of the given individual numbers


using System;

using System.Collections.Generic;

namespace ConsolePractice

{

    class Program

    {

        static void Main(string[] args)

        {

            int no = 7895;

            int r = 0;

            int sum = 0;

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

            {

                r = no % 10; // moduler is used to identitify the units place

                sum = sum + (r*r); // for suqres use 2 times reminders and for                                                    cubes use three time reminder

                no = no / 10; // by is used to delete the units place

            }

            Console.WriteLine("sum of the given digits" + sum);

            Console.ReadLine();

        }

    }

}




Reverse the given Number



using System.Collections.Generic;

namespace ConsolePractice

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("Enter number to reverse the given number");

            int no = int.Parse(Console.ReadLine());

            int r = 0;

            int rev = 0;

            int noLength = no.ToString().Length;

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

            {

                r = no % 10;

                rev = (rev * 10) + r;

                no = no / 10;

            }

            Console.WriteLine("The Reverse Number is rev= "+rev);

            Console.ReadLine();

        }

    }

}            



Check the given number is Palindrome Number or not



using System;

using System.Collections.Generic;

namespace ConsolePractice

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("Enter number to reverse the given number");

            int no = int.Parse(Console.ReadLine());

            int r = 0;

            int rev = 0;

            int revNum = no;

            int noLength = no.ToString().Length;

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

            {

                r = no % 10;

                rev = (rev * 10) + r;

                no = no / 10;

            }

            if (revNum== rev)

            {

             Console.WriteLine("The Reverse Number is Palindrome rev= " + rev);

            }

            else

            {

                Console.WriteLine("Number is Not Palindrome Number ");

            }

         

            Console.ReadLine();

        }

    }

}       




Check the given number is Armstrong Number or not



 using System;

using System.Collections.Generic;

namespace ConsolePractice

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("Enter number to reverse the given number");

            int no = int.Parse(Console.ReadLine());

            int r = 0;

            int cube = 0;

            int revNum = no;

            int noLength = no.ToString().Length;

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

            {

                r = no % 10;

                cube = cube + (r*r*r);

                no = no / 10;

            }

            if (revNum== cube)

            {

                Console.WriteLine("The Reverse Number is Armstrong rev= " + revNum);

            }

            else

            {

                Console.WriteLine("Number is Not Armstrong Number ");

            }

         

            Console.ReadLine();

        }

    }

}

          




Previous Post Next Post