コード例 #1
0
        public static void Ex20()
        {
            Console.WriteLine("Please place your order: ");
            int    tv  = ISSConsole.ReadInt("Quantity of TV: ");
            int    dvd = ISSConsole.ReadInt("Quantity of DVD: ");
            int    mp3 = ISSConsole.ReadInt("Quantity of MP3: ");
            double discount;
            int    firstCost = tv * 900 + dvd * 500 + mp3 * 700;

            if (firstCost >= 10000)
            {
                discount = 0.15;
            }
            else if (firstCost >= 5000)
            {
                discount = 0.1;
            }
            else
            {
                discount = 0;
            }
            double totalCost = (tv * 900 + dvd * 500) * (discount + 1) + mp3 * 700;

            Console.WriteLine($"Total amount is: {totalCost}");
        }
コード例 #2
0
ファイル: Ex17.cs プロジェクト: vigneshwarikandan/class
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your name");
            string username = ISSConsole.ReadString();

            Console.WriteLine("Enter your gender");
            char gender = ISSConsole.ReadChar();

            Console.WriteLine("Enter your age");
            int age = ISSConsole.ReadInt();

            if (gender == 'M')
            {
                if (age >= 40)
                {
                    Console.WriteLine("Good morning Uncle {0}", username);
                }
                else
                {
                    Console.WriteLine("Good morning Mr {0}", username);
                }
            }
            else
            {
                if (age >= 40)
                {
                    Console.WriteLine("Good morning Aunty {0}", username);
                }
                else
                {
                    Console.WriteLine("Good morning Ms. {0}", username);
                }
            }
        }
コード例 #3
0
        public static void Ex15()
        {
            Console.Write("Please insert a number to check if it is Armstrong number: ");
            string a   = ISSConsole.ReadString();
            int    num = Convert.ToInt32(a);
            double sum = 0;

            /*for (int i = 0; i < 3; i++)
             * {
             *  char b = a[i];
             *  int c = Convert.ToInt32(new string(b, 1));
             *  sum += c * c * c;
             * }*/
            int digits = a.Length;

            for (int i = num; i > 0; i /= 10)
            {
                int rem = i % 10;
                sum += Math.Pow(rem, digits);
            }
            if (sum == num)
            {
                Console.WriteLine($"{a} is an Armstrong number.");
            }
            else
            {
                Console.WriteLine($"{a} is not an Armstrong number.");
            }
        }
コード例 #4
0
        public static void Ex18()
        {
            int marks = ISSConsole.ReadInt("Please input your Marks: ");

            if (marks > 0 && marks < 100)
            {
                char grade; //Declaring
                if (marks >= 80)
                {
                    grade = 'A';
                }
                else if (marks >= 60)
                {
                    grade = 'B';
                }
                else if (marks >= 40)
                {
                    grade = 'C';
                }
                else
                {
                    grade = 'F';
                }
                Console.WriteLine($"You scored {marks} marks which is {grade} grade.");
            }
            else
            {
                Console.WriteLine("**Error**");
            }
        }
コード例 #5
0
ファイル: Ex20.cs プロジェクト: vigneshwarikandan/class
        static void Main(string[] args)
        {
            Console.Write("Enter the ordered quantity of TV");
            int q_tv = ISSConsole.ReadInt();

            Console.Write("Enter the ordered quantity of DVD");
            int q_dvd = ISSConsole.ReadInt();

            Console.Write("Enter the ordered quantity of MP3");
            int q_mp3 = ISSConsole.ReadInt();

            int price_tv  = 900;
            int price_dvd = 500;
            int price_mp3 = 700;

            double tv_orderedAmount = price_tv * q_tv;
            double dvd_orderAmount  = price_dvd * q_dvd;
            double mp3_orderAmount  = price_mp3 * q_mp3;

            double totalOrderAmount = tv_orderedAmount + dvd_orderAmount + mp3_orderAmount;

            Console.WriteLine("The total ordered amount without discount=" + totalOrderAmount);

            if (totalOrderAmount > 5000 && totalOrderAmount < 10000)
            {
                totalOrderAmount = totalOrderAmount - totalOrderAmount * 0.1;
            }
            else if (totalOrderAmount > 10000)
            {
                totalOrderAmount = totalOrderAmount - totalOrderAmount * 0.15;
            }

            Console.WriteLine("The total ordered amount with discount=" + totalOrderAmount);
        }
コード例 #6
0
        public static void Ex33()
        {
            int temp;
            int n = ISSConsole.ReadInt("Please insert length of array: ");

            int[] array = new int[n];
            for (int i = 0; i < n; i++)
            {
                array[i] = ISSMath.RNDInt(100);
                Console.Write($"\t{array[i]}");
            }
            Console.WriteLine();
            Console.WriteLine("Simplified seclection sort method progess:");
            for (int i = 0; i < n - 1; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    if (array[i] < array[j])
                    {
                        temp     = array[i];
                        array[i] = array[j];
                        array[j] = temp;
                        for (int l = 0; l < n; l++)
                        {
                            Console.Write($"\t{array[l]}");
                        }
                        Console.WriteLine();
                    }
                }
            }
        }
コード例 #7
0
        public static void Ex32()
        {
            int[] sales = new int[12];
            for (int i = 0; i < 12; i++)
            {
                sales[i] = ISSConsole.ReadInt($"Please enter sales of month {i}: ");
            }
            int min = sales[0], max = sales[0];
            int monthMin = 0, monthMax = 0;
            int sum = sales[0];

            for (int i = 1; i < 12; i++)
            {
                sum += sales[i];
                if (sales[i] < min)
                {
                    min      = sales[i];
                    monthMin = i;
                }
                if (sales[i] > max)
                {
                    max      = sales[i];
                    monthMax = i;
                }
            }
            Console.WriteLine($"The month with Maximum sales is {monthMax}");
            Console.WriteLine($"The month with Minimum sales is {monthMin}");
            Console.WriteLine($"The average monthly sales is {(double)sum/12:c}");
        }
コード例 #8
0
        static void Main(string[] args)
        {
            Console.Write("Enter a number to find whether it is perfect");
            int number = ISSConsole.ReadInt();
            int pn     = 0;

            // findOdd();
            for (int i = 1; i < number; i++)
            {
                if (number == 6)
                {
                    pn = pn + i;
                    if (pn == number)
                    {
                        System.Console.WriteLine("Perfect number");
                        break;
                    }
                }
                else
                {
                    for (int k = 1; k < 30; k++)
                    {
                        if (k % 2 != 0)
                        {
                            pn = pn + (int)Math.Pow(k, 3);
                            if (pn == number)
                            {
                                System.Console.WriteLine("Perfect number");
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #9
0
        static void Main(string[] args)
        {
            int comp_mind = ISSMath.RNDInt(9);

            Console.WriteLine("In my mind=" + comp_mind);
            int yourguess;
            int count = 0;

            do
            {
                if (count >= 1)
                {
                    Console.WriteLine("Try again");
                }
                yourguess = ISSConsole.ReadInt("Guess the number in my mind");
                ++count;
            } while (comp_mind != yourguess);
            if (count <= 2)
            {
                Console.WriteLine("Congrats. you have made {0} attempts", count);
                Console.WriteLine("You are a wizard");
            }
            else if (count >= 3 && count <= 5)
            {
                Console.WriteLine("You are a good guess");
            }
            else
            {
                Console.WriteLine("Your are lousy");
            }
        }
コード例 #10
0
        public static void Ex22()
        {
            int RandomInteger = ISSMath.RNDInt(10);

            Console.WriteLine("Welcome to the Guess the Number Game!!");
            Console.WriteLine("Please insert a number (0~9): ");
            int count = 0;
            int guess;

            do
            {
                guess = ISSConsole.ReadInt();
                if (guess != RandomInteger)
                {
                    Console.WriteLine("Please try again!");
                    count++;
                }
                else
                {
                    if (count <= 1)
                    {
                        Console.WriteLine("You are a Wizard!");
                    }
                    else if (count <= 4)
                    {
                        Console.WriteLine("You are a good guess!");
                    }
                    else if (count <= 9)
                    {
                        Console.WriteLine("You are lousy!");
                    }
                }
            }while (guess != RandomInteger);
        }
コード例 #11
0
ファイル: Exercise1.cs プロジェクト: vigneshwarikandan/class
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your name");
            string username = ISSConsole.ReadString();

            Console.WriteLine("Good morning " + username);
        }
コード例 #12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your score");
            int score = ISSConsole.ReadInt();

            // char grade;
            if (score >= 80 && score <= 100)
            {
                Console.WriteLine("You scored {0} marks which is A grade", score);
            }
            else if (score >= 60 && score <= 79)
            {
                Console.WriteLine("You scored {0} marks which is B grade", score);
            }
            else if (score >= 40 && score <= 59)
            {
                Console.WriteLine("You scored {0} marks which is C grade", score);
            }
            else if (score >= 0 && score <= 40)
            {
                Console.WriteLine("You scored {0} marks which is F grade", score);
            }
            else if (score < 0)
            {
                Console.WriteLine("**Error**");
            }
            else if (score > 100)
            {
                Console.WriteLine("**Error**");
            }
        }
コード例 #13
0
        public static void Ex26()
        {
            int    n      = ISSConsole.ReadInt("Please key in a number to check if it is Prime: ");
            string result = " ";

            while (n < 0)
            {
                Console.WriteLine("Please insert a positive number...");
                n = ISSConsole.ReadInt();
            }
            if (n == 1 || n == 2)
            {
                result = "Prime.";
            }
            else
            {
                for (int i = 2; i <= n / 2; i++)
                {
                    if (n % i == 0)
                    {
                        result = "Not Prime.";
                    }
                    else
                    {
                        result = "Prime.";
                    }
                }
            }
            Console.WriteLine(result);
        }
コード例 #14
0
ファイル: armstrong.cs プロジェクト: vigneshwarikandan/class
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a 3 digit number");
            int number = ISSConsole.ReadInt();
            int q      = number;
            int r      = 0;
            int sum    = 0;

            q   = number / 100;
            r   = number % 100;
            sum = (int)Math.Pow(q, 3);

            q   = r / 10;
            r   = r % 10;
            sum = sum + (int)Math.Pow(q, 3);

            sum = sum + (int)Math.Pow(r, 3);
            if (sum == number)
            {
                System.Console.WriteLine("The number is an armstrong number");
            }
            else
            {
                System.Console.WriteLine("The number is not an armstrong number");
            }
        }
コード例 #15
0
ファイル: Ex22.cs プロジェクト: vigneshwarikandan/class
        static void Main(string[] args)
        {
            int tempa, tempb;

            Console.WriteLine("Enter 2 numbers");
            int a   = tempa = ISSConsole.ReadInt();
            int b   = tempb = ISSConsole.ReadInt();
            int hcf = 0;

            while (a != b)
            {
                if (b > a)
                {
                    b   = b - a;
                    hcf = b;
                }
                else
                {
                    a   = a - b;
                    hcf = a;
                }
            }

            Console.WriteLine("HCF={0}", hcf);

            Console.WriteLine("LCM={0}", tempa * tempb / hcf);
        }
コード例 #16
0
ファイル: Exercise1.cs プロジェクト: vigneshwarikandan/class
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a double precision number");
            double number             = ISSConsole.ReadDouble();
            double squareRootOfNumber = Math.Sqrt(number);

            Console.WriteLine("The square root of the number" + squareRootOfNumber);
        }
コード例 #17
0
ファイル: Exercise1.cs プロジェクト: vigneshwarikandan/class
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a double precision number");
            double doubleNumber = ISSConsole.ReadDouble();
            double squareDouble = doubleNumber * doubleNumber;

            Console.WriteLine("the square of double precision number is =" + squareDouble);
        }
コード例 #18
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the km");
            double kmsTravelled = ISSConsole.ReadDouble();
            double fare         = 2.40 + kmsTravelled * 0.4;

            Console.WriteLine("The fare is {0:##.#0}", Math.Round(fare, 1));
        }
コード例 #19
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the value of x");
            double x = ISSConsole.ReadDouble();
            double y = 5 * Math.Pow(x, 2) - 4 * x + 3;

            Console.WriteLine("The value of y is " + y);
        }
コード例 #20
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the centigrade");
            double C          = ISSConsole.ReadDouble();
            double fahrenheit = 1.8 * C + 32;

            Console.WriteLine("The fahrenheit is " + fahrenheit);
        }
コード例 #21
0
        public static void Ex44() //Character replacement program
        {
            string s  = ISSConsole.ReadString("Please insert string: ");
            char   c1 = ISSConsole.ReadChar("Character to be replaced: ");
            char   c2 = ISSConsole.ReadChar("Character chosen to replace: ");

            substitute(s, c1, c2);
        }
コード例 #22
0
ファイル: Exercise1.cs プロジェクト: vigneshwarikandan/class
        static void Main(string[] args)
        {
            Console.WriteLine("Enter an integer");
            int    number  = ISSConsole.ReadInt();
            double sqrtInt = Math.Sqrt(number);

            Console.WriteLine("The square root of {0} is {1}", number, sqrtInt);
            ISSConsole.Pause();
        }
コード例 #23
0
ファイル: Exercise1.cs プロジェクト: vigneshwarikandan/class
        //Can we write string args[]?
        static void Main(string[] args)
        {
            Console.WriteLine("Enter an integer");
            int number = ISSConsole.ReadInt();
            //We have Math.pow
            int squareOfNumber = number * number;

            Console.WriteLine("square of the number is=" + squareOfNumber);
        }
コード例 #24
0
        // ------------------ STRING MANIPULATION TEEHEE --------------------------------//

        public static void Ex36() //PALINDROME
        {
            string s = ISSConsole.ReadString("Please insert a string to check if it is a Palindrome:");

            s = s.ToLower();         //Properties to convert all to lower
            int    n     = s.Length; //Assign to a length of the string to a variable
            bool   check = true;
            string r     = "";

            for (int i = 0; i < n; i++)
            {
                string letter = s.Substring(i, 1);                            //First parameter determines the starting index and strings starts with [0],
                                                                              //the second parameter determines the amount of char to concatenate
                                                                              //this step breaks it down into individual letters and assign it to letter

                if (letter.CompareTo("a") >= 0 && letter.CompareTo("z") <= 0) //method instance ** Clarify this part from StackOverflow
                {
                    r += letter;
                }
            }
            //Program
            for (int i = 0; i < r.Length; i++)
            {
                if (r[n - 1 - i] != r[i])
                { //if
                    check = false;
                }
            }
            if (check != false)
            {
                Console.WriteLine($"{s} is a Palindrome.");
            }
            else
            {
                Console.WriteLine($"{s} is not a Palindrome.");
            }

            //more elegant code

            //public static boolean Palindrom(char[] word)
            //{
            //    int i1 = 0;
            //    int i2 = word.length - 1;
            //    while (i2 > i1)
            //    {
            //        if (word[i1] != word[i2])
            //        {
            //            return false;
            //        }
            //        ++i1;
            //        --i2;
            //    }
            //    return true;
            //}
        }
コード例 #25
0
ファイル: Exercise1.cs プロジェクト: vigneshwarikandan/class
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a double precision number to find square root and round to 3 decimals");
            double number = ISSConsole.ReadDouble();
            double sqrt   = Math.Sqrt(number);
            double round3 = Math.Round(sqrt);

            Console.WriteLine("The square root of " + number + " is " + sqrt + " \n" + "It is rounded of to 3 decimals as {0:##.###}", sqrt);
            // Console.WriteLine("The square root of " + number + " is " + sqrt);
            //Console.WriteLine("The rounded value is {0:##.000}" , sqrt);
        }
コード例 #26
0
        public static void Ex21()
        {
            int x;

            do
            {
                Console.Write("Please key a number: ");
                x = ISSConsole.ReadInt();
            }while (x != 88);
            Console.WriteLine("Lucky you...");
        }
コード例 #27
0
        public static void Ex24()
        {
            int    n = ISSConsole.ReadInt("Please input number to find it's squart root: ");
            double g = ISSMath.RND();

            while (g * g != n)
            {
                g = (g + n / g) / 2;
            }
            Console.WriteLine($"Squart root of {n} is {g}");
        }
コード例 #28
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a number for factorial");
            int number    = ISSConsole.ReadInt();
            int factorial = 1;

            for (int i = 1; i <= 5; i++)
            {
                factorial = factorial * i;
            }
            Console.WriteLine("The factorial is {0}", factorial);
        }
コード例 #29
0
        static void Main(string[] args)
        {
            //do while
            int number = 0;

            do
            {
                Console.WriteLine("Enter a number");
                number = ISSConsole.ReadInt();
            } while (number != 88);
            Console.WriteLine("Lucky you");
        }
コード例 #30
0
ファイル: Ex23.cs プロジェクト: vigneshwarikandan/class
        static void Main(string[] args)
        {
            int comp_mind = ISSMath.RNDInt(9);
            int yourguess;
            int count = 0;

            do
            {
                yourguess = ISSConsole.ReadInt("Guess the number in my mind");
                ++count;
            } while (comp_mind != yourguess);
            Console.WriteLine("Congrats. your have made {0} attempts", count);
        }