Ejemplo n.º 1
0
        public void CalculateTest(double firstValue, double expected)
        {
            var calculator   = new ReverseNumber();
            var actualResult = calculator.Calculate(firstValue);

            Assert.AreEqual(expected, actualResult, 0.01);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            NumberOfIslands number = new NumberOfIslands();

            Console.WriteLine(number.IslandCount());

            SpiralPrint sp = new SpiralPrint();

            sp.Print();

            PascalTriangle pt = new PascalTriangle();

            pt.Generate(6); pt.Print();

            MedianOfSortedArrays ms = new MedianOfSortedArrays();

            Console.WriteLine(ms.MedianOf2SortedArrays(ms.array1, ms.array2));

            FindtheMissingNumber fn = new FindtheMissingNumber();

            Console.WriteLine(fn.FindtheMissingNumberMethod1());

            ContainsDuplicate cd = new ContainsDuplicate();

            Console.WriteLine(cd.isDuplicateMethod2());

            ReversedLinkedList rl = new ReversedLinkedList();

            rl.reversedList();

            ReverseNumber rn = new ReverseNumber();

            rn.ReverseANumber(12345);

            LinearSearch ls = new LinearSearch();
            BinarySearch bs = new BinarySearch();

            ZigZag zz = new ZigZag();

            Console.WriteLine(zz.Convert("PAYPALISHIRING", 3));

            BinaryTree bt = new BinaryTree();

            bt.InorderTraverse(bt.root);
            Console.WriteLine();
            bt.PreorderTraverse(bt.root);
            Console.WriteLine();
            bt.PostorderTraverse(bt.root);

            RotateArray ra = new RotateArray(3);
            //SearchRotatedArray sr = new SearchRotatedArray(3);
            //Console.WriteLine(sr.Find());

            FindSumSarray  fS    = new FindSumSarray();
            MaxSumSubArray mxSum = new MaxSumSubArray();
        }
        public static bool IsPalindrome(int n)
        {
            int nRev = ReverseNumber.Reverse(n);

            if (nRev == n)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
    public static void Main(string[] args)
    {
        var myClass = new ReverseNumber();

        Console.Write("Enter an integer: ");
        decimal numberToReverse = decimal.Parse(Console.ReadLine());

        Console.WriteLine();
        Console.WriteLine(new string('-', 30));

        decimal reversedNumber = myClass.ReverseInteger(numberToReverse);

        Console.WriteLine("\nReversed integer is {0}", reversedNumber);
    }
    static void Main()
    {
        int choise = UserChoise();

        if (choise == 1)
        {
            Console.WriteLine("Enter the number you want to reverse");
            ReverseNumber.Reverse(); // Here I use the method from exercise 7
        }
        if (choise == 2)
        {
            AverageSequenceOfIntegers();
        }
        if (choise == 3)
        {
            SolveLinearEquation();
        }
    }
Ejemplo n.º 6
0
    static void Main()
    {
        Console.WriteLine(
            @"Choose one of those
Press 1 for Reverses the digits of a number :
Press 2 for Calculates the average of a sequence of integers : ");

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

        if (type == 1)
        {
            Console.WriteLine("Enter number");
            int number = int.Parse(Console.ReadLine());
            Console.WriteLine(ReverseNumber.RevertNumber(number));
        }

        if (type == 2)
        {
            Console.WriteLine("Enter number");
            string number = Console.ReadLine();
            double result = (AverageOfASequenceOfIntegers.Average(number));
            Console.WriteLine(result);
        }
    }
Ejemplo n.º 7
0
        public void SelectChoice(int choice)
        {
            switch (choice)
            {
            case 1:
            {
                Console.Write("Age program started \n");

                Student s = new Student();
                s.name = "Nikhil";
                Console.WriteLine("Enter Age : ");
                var age = Convert.ToInt32(Console.ReadLine());
                s.SetAge(age);
                if (age > 0 && age < 100)
                {
                    Console.WriteLine("\n Your age is" + s.GetAge());
                }
                break;
            }

            case 2:
            {
                Console.Write("Addition program started \n");

                Addition addition = new Addition();
                Console.Write("Enter first number: ");
                var firstNumber = Convert.ToInt32(Console.ReadLine());
                Console.Write("Enter second number: ");
                var secondNumber = Convert.ToInt32(Console.ReadLine());
                var result       = addition.AdditionOfTwoNumbers(firstNumber, secondNumber);
                Console.Write("{0}+{1}={2}", firstNumber, secondNumber, result);
                Console.ReadKey();
                break;
            }

            case 3:
            {
                Console.Write("Multiplication program started \n");

                Multiplication multiplication = new Multiplication();
                Console.Write("\n Enter First Number: ");
                var firstNumber = Convert.ToInt32(Console.ReadLine());
                Console.Write("Enter Second Number: ");
                var secondNumber = Convert.ToInt32(Console.ReadLine());
                var result       = multiplication.MultiplicationOfTwoNumber(firstNumber, secondNumber);
                Console.Write("{0}*{1}={2}", firstNumber, secondNumber, result);
                Console.ReadKey();
                break;
            }

            case 4:
            {
                Console.Write("Factorial program started \n");
                Factorial factorial = new Factorial();
                Console.Write("\n Enter number for calcuationg factorial");
                var number = Convert.ToInt32(Console.ReadLine());
                var fact   = factorial.CalculateFactorial(number);
                Console.Write("Result is: " + fact);
                break;
            }

            case 5:
            {
                Console.Write("Palindrome program started \n");
                Palindrome palindrome = new Palindrome();
                Console.Write("\n Enter number for palindrome");
                var number = Convert.ToInt32(Console.ReadLine());
                var sum    = palindrome.palindromenumber(number);
                break;
            }

            case 6:
            {
                Console.Write("sum of digit program started \n");
                Sum_of_digit sumofdigit = new Sum_of_digit();
                Console.Write("\n Enter number for sum of digit");
                var number = Convert.ToInt32(Console.ReadLine());
                var sum    = sumofdigit.NumberOfDigit(number);
                Console.Write("Result is: " + sum);
                break;
            }

            case 7:
            {
                Console.Write("Armstrom program started \n");
                Armstrong armstrong = new Armstrong();
                Console.Write("Enter number for armstrong");
                var number = Convert.ToInt32(Console.ReadLine());
                var sum    = armstrong.arm(number);
                break;
            }

            case 8:
            {
                Console.Write("Table program started print inside \n");
                Table table = new Table();
                Console.Write("Enter number For find out table");
                var number = int.Parse(Console.ReadLine());
                table.CalculateTableInsidePrint(number);
                break;
            }


            case 9:
            {
                Console.Write("Tables program started print outside  \n");
                Multiplication multiplication = new Multiplication();
                Console.Write("Enter first number");
                var firstNumber = int.Parse(Console.ReadLine());
                for (int secondNumber = 1; secondNumber <= 10; secondNumber++)
                {
                    var multi = multiplication.MultiplicationOfTwoNumber(firstNumber, secondNumber);
                    Console.Write("{0}*{1}={2} \n", firstNumber, secondNumber, multi);
                }
                break;
            }

            case 10:
            {
                Console.Write("Division program started");
                Division division = new Division();
                Console.Write("Enter first number");
                var firstNumber = int.Parse(Console.ReadLine());
                Console.Write("Enter second number");
                var secondNumber = int.Parse(Console.ReadLine());
                var divide       = division.DivideTwoNumbers(firstNumber, secondNumber);
                Console.Write("{0}/{1}={2}", firstNumber, secondNumber, divide);
                break;
            }

            case 11:
            {
                Console.Write("Reverse number program started");
                ReverseNumber revesenumber = new ReverseNumber();
                Console.Write("Enter a number");
                var number = int.Parse(Console.ReadLine());
                var rev    = revesenumber.CalculateReverseNumber(number);
                Console.Write("Result is: " + rev);
                break;
            }

            case 12:
            {
                Console.Write("Swap program started");
                Swap swap = new Swap();
                Console.Write("Enter first number");
                var firstNumber = int.Parse(Console.ReadLine());
                Console.Write("Enter second number");
                var secondNumber = int.Parse(Console.ReadLine());
                swap.SwapTwoNumbers(firstNumber, secondNumber);
                break;
            }

            case 13:
            {
                Console.Write("swap program started without temp variable");
                Swap swap = new Swap();
                Console.Write("Enter first number");
                var firstNumber = int.Parse(Console.ReadLine());
                Console.Write("Enter second number");
                var secondNumber = int.Parse(Console.ReadLine());
                swap.SwapwithoutTemp(firstNumber, secondNumber);
                break;
            }


            case 14:
            {
                Console.Write("Prime number program started");
                PrimeNumber primenumber = new PrimeNumber();
                Console.WriteLine("Enter a number");
                var number = int.Parse(Console.ReadLine());
                primenumber.CheckPrime(number);
                break;
            }

            case 15:
            {
                Console.Write("String count program started");
                StringCountring stringcounting = new StringCountring();
                Console.Write("Enter a string : ");
                var str   = Console.ReadLine();
                var count = (stringcounting.countstring(str));
                Console.Write("Counting of string is " + count);
                break;
            }

            case 16:
            {
                Console.Write("Substring program started");
                Substring substring = new Substring();
                Console.Write("enter a string \n");
                var givenString = Console.ReadLine();
                Console.Write("enter word in string");
                var subString = Console.ReadLine();
                substring.findOutSubString(givenString, subString);
                break;
            }

            case 17:
            {
                Console.Write("List of string program started");

                ListOfString liststring = new ListOfString();

                Console.WriteLine("\n How many item");
                var howItem = int.Parse(Console.ReadLine());
                liststring.InsertAndDisplayListOfString(howItem);
                break;
            }

            case 18:
            {
                Console.Write("Pyramid Dispaly pattern program started \n");
                DispalyPattern displaypattern = new DispalyPattern();
                Console.WriteLine("enter value");
                int number = int.Parse(Console.ReadLine());
                displaypattern.PyramidDesignPattern(number);
                break;
            }

            case 19:
            {
                Console.Write("Square Dispaly pattern program started \n");
                DispalyPattern displaypattern = new DispalyPattern();
                Console.WriteLine("how many vertical number");
                var firstNumber = int.Parse(Console.ReadLine());
                Console.WriteLine("how many horizontal number");
                var secondNumber = int.Parse(Console.ReadLine());
                displaypattern.SquareDesignPattern(firstNumber, secondNumber);
                break;
            }

            case 20:
            {
                Console.Write("Array of integer program started \n");
                ArrayOfInteger arrayofinteger = new ArrayOfInteger();
                Console.Write("How many numbers do you want to add in an array :");
                var sizeOfArray = int.Parse(Console.ReadLine());
                arrayofinteger.ArrayOperation(sizeOfArray);
                break;
            }

            case 21:
            {
                Console.Write("List of integer which number is not present in the list \n");
                FindMissingNumber findMissingNumber = new FindMissingNumber();
                Console.Write("Plese enter size of list");
                int number = int.Parse(Console.ReadLine());
                findMissingNumber.FindMissingNumbers(number);
                break;
            }


            case 22:
            {
                Console.Write("Largest number program started \n");
                LargestNumber largestnumber = new LargestNumber();
                Console.Write("Plese enter size of list");
                int number = int.Parse(Console.ReadLine());
                largestnumber.FindLargestNumber(number);
                break;
            }

            case 23:
            {
                Console.Write("number is available or not program started \n");
                AvailableNoOrNot availableNoOrNot = new AvailableNoOrNot();
                Console.Write("Please enter size of list");
                int number = int.Parse(Console.ReadLine());
                availableNoOrNot.FindNumber(number);
                break;
            }

            default:
                Console.Write("No match found");
                break;
            }
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            decimal numb  = 0;
            decimal numbB = 0;
            string  input = "123";

            Console.WriteLine("1. Reverses the digits of a number");
            Console.WriteLine("2. Calculate the average of a sequence of integers");
            Console.WriteLine("3. Solve a linear equation a * x + b = 0");
            Console.Write("Please enter your choise: ");
            int choice = int.Parse(Console.ReadLine());

            Console.Clear();
            switch (choice)
            {
            case 1:
            {
                do
                {
                    if (numb < 0)
                    {
                        Console.WriteLine("Non-negative!!!");
                    }
                    Console.Write("Please enter a non-negative number: ");
                    numb = decimal.Parse(Console.ReadLine());
                } while (numb < 0);
                Console.WriteLine(ReverseNumber.ReverseNumb(numb));
                break;
            }

            case 2:
            {
                do
                {
                    if (input.Length < 1)
                    {
                        Console.WriteLine("The sequence should not be empty!");
                    }
                    Console.Write("Please enter a sequence of numbers: ");
                    input = Console.ReadLine();
                } while (input.Length < 1);
                string[] arrAsStr = input.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                int[]    arr      = new int[arrAsStr.Length];
                decimal  sum      = 0;
                for (int i = 0; i < arrAsStr.Length; i++)
                {
                    arr[i] = int.Parse(arrAsStr[i]);
                    sum   += arr[i];
                }
                Console.WriteLine("\nAverage is: {0}", sum / arr.Length);
                break;
            }

            case 3:
            {
                do
                {
                    if (numb == 0)
                    {
                        Console.WriteLine("A should not be equal to 0!");
                    }
                    Console.Write("A= ");
                    numb = decimal.Parse(Console.ReadLine());
                } while (numb == 0);
                Console.Write("B= ");
                numbB = decimal.Parse(Console.ReadLine());
                Console.WriteLine("X= {0}", -numbB / numb);
                break;
            }

            default: Console.WriteLine("Incorect choise!");
                break;
            }
            //  );
        }
Ejemplo n.º 9
0
        public static string Process(string input1, string input2, string input3)
        {
            string output = string.Empty;

            switch (input3)
            {
            case "add":
                output = Addition.Add(input1, input2).ToString();
                break;

            case "subtraction":
                output = Subtraction.Sub(input1, input2).ToString();
                break;

            case "multiplication":
                output = Multiplication.Mul(input1, input2).ToString();
                break;

            case "division":
                output = Division.Div(input1, input2).ToString();
                break;

            case "divby3notby6":
                output = Divisionbythreenotbysix.Run(input1).ToString();
                break;

            case "armstrongornot":
                output = Armstrongnumber.Check(input1).ToString();
                break;

            case "factorial":
                output = Factorial.Calculate(input1).ToString();
                break;

            case "palindrome":
                output = PalindromeNumber.Find(input1).ToString();
                break;

            case "reverse":
                output = ReverseNumber.Reverse(input1).ToString();
                break;

            case "sumofdigits":
                output = Sumofdigits.Find(input1).ToString();
                break;

            case "decimaltobinary":
                output = DecimaltoBinary.Converts(input1).ToString();
                break;

            case "numberincharacter":
                output = NumbersInCharacters.Print(input1).ToString();
                break;

            case "strreverse":
                output = StringReverse.Reverse(input1).ToString();
                break;

            case "duplicate":
                output = DuplicateElement.Find(input1).ToString();
                break;

            case "unique":
                output = UniqueElement.Return(input1).ToString();
                break;

            case "strpalindrome":
                output = StringPalindrome.Find(input1).ToString();
                break;

            case "length":
                output = StringLength.Calculate(input1).ToString();
                break;

            case "vowels":
                output = NumofVowels.Print(input1).ToString();
                break;

            case "search":
                output = CharacterSearching.Search(input1, input2).ToString();
                break;

            case "count":
                output = WordCount.Count(input1).ToString();
                break;

            case "date":
                output = DateandTime.Calculate(input1).ToString();
                break;
            }
            return(output);
        }
Ejemplo n.º 10
0
        public void ExceptionTest(double firstArgument)
        {
            var calculator = new ReverseNumber(); ();

            Assert.Throws <Exception>(() => calculator.Calculate(firstArgument));
        }