/// <summary> /// A five-digit number is entered through the keyboard. /// Write a program to obtain the reversed number and to determine /// whether the original and reversed numbers are equal or not /// </summary> /// <param name=""></param> public static void ReverseOfFiveDigitNumberisSame(this Chapter_02.ProfitAndLoss inputClass) { Console.WriteLine("Enter Five digit Number"); int inputnumber = Convert.ToInt32(Console.ReadLine()); int refinput = inputnumber; if (inputnumber >= 100000) { Console.WriteLine("please enter 5 digits only "); } else { int Reverse = 0; while (inputnumber > 0) { Reverse = Reverse * 10 + (inputnumber % 10); inputnumber = inputnumber / 10; } // Console.WriteLine($"Reverse of the {refinput} is {Reverse}"); if (refinput != Reverse) { Console.WriteLine("both Numbers are Different"); } else { Console.WriteLine("Both the Numbers are equal"); } } }
/// <summary> /// If the time taken by the worker is input through the keyboard, /// find the efficiency of the worker. /// </summary> public static void FindWorkerEfficiency(this Chapter_02.ProfitAndLoss className) { Console.WriteLine("Enter the Time taken by the worker"); int timeTakenByworker = Convert.ToInt32(Console.ReadLine()); if (timeTakenByworker <= 5) { if (timeTakenByworker <= 3) { if (timeTakenByworker < 2) { Console.WriteLine("worker is highly efficient"); } else { Console.WriteLine("the worker is ordered to improve speed"); } } else { Console.WriteLine("the worker is given training to improve his speed"); } } else { Console.WriteLine("Worker Can Leave The company"); } }
/// <summary> ///A library charges a fine for every book returned late. For first ///5 days the fine is 50 paise, for 6-10 days fine is one rupee and ///above 10 days fine is 5 rupees. If you return the book after 30 ///days your membership will be cancel. Write a program to ///accept the number of days the member is late to return the ///book and display the fine or the appropriate message. /// </summary> /// <param name="classname"></param> public static void LateReturnChargeofBook(this Chapter_02.ProfitAndLoss classname) { Console.WriteLine("Enter the days of late return"); int Latereturndays = Convert.ToInt32(Console.ReadLine()); if (Latereturndays < 30) { if (Latereturndays < 09) { if (Latereturndays < 5) { Console.WriteLine(" fine is 50 paise"); } else { Console.WriteLine("fine is one rupee"); } } else { Console.WriteLine("fine is five rupees"); } } else { Console.WriteLine("Membership is Canceled "); } }
/// <summary> ///If the three sides of a triangle are entered through the keyboard, ///write a program to check whether the triangle is isosceles, equilateral, scalene or right angled triangle. /// </summary> public static void TriangleBasedonAngles(this Chapter_02.ProfitAndLoss ClassName) { Console.WriteLine("Enter Angle A of triangle"); Console.WriteLine("Enter Angle B"); Console.WriteLine("Enter Angle C"); int angleA = Convert.ToInt32(Console.ReadLine()); int angleB = Convert.ToInt32(Console.ReadLine()); int angleC = Convert.ToInt32(Console.ReadLine()); if (angleA + angleB + angleC == 180) { if (angleA == angleB && angleA == angleC && angleB == angleC) { Console.WriteLine("its a equilateral"); } else if (angleA == 90 || angleB == 90 || angleC == 90) { Console.WriteLine("its a Right angle Triangle "); } else if (angleA != angleB && angleA != angleC && angleB != angleC) { Console.WriteLine("its a scalene "); } if (angleA == angleB || angleA == angleC || angleB == angleC) { Console.WriteLine("its a isosceles"); } } else { Console.WriteLine("its not a Triangle"); } }
/// <summary> /// Any year is input through the keyboard. Write a program to /// determine whether the year is a leap year or not. /// </summary> /// <param name="Chapter2"></param> public static void IsGivenYearisLeapyear(this Chapter_02.ProfitAndLoss Chapter2) { Console.WriteLine("Enter Year"); int inputYear = Convert.ToInt32(Console.ReadLine()); string leapYear = (inputYear % 4 == 0) ? "leap year":"not leap year"; Console.WriteLine($"Given Year is a {leapYear}"); }
/// <summary> /// Find the absolute value of a number entered through the keyboard. /// number less than zero should be multiplied with - value /// </summary> /// <param name="ClassName"></param> public static void FindtheAbsoluteValueofANumber(this Chapter_02.ProfitAndLoss ClassName) { Console.WriteLine("enter the value"); int number = Convert.ToInt32(Console.ReadLine()); //Math.Abs(number); if (number < 0) { number = number * (-1); } Console.WriteLine($"absolute value of a number is {number}"); }
/// <summary> /// Given the length and breadth of a rectangle, /// write a program to find whether the area of the rectangle is greater than its perimeter. /// For example, /// the area of the rectangle with length = 5 and /// breadth = 4 is greater than its perimeter /// </summary> /// <param name="ClassName"></param> public static void Areaoftherectangleisgreaterthanitsperimeter(this Chapter_02.ProfitAndLoss ClassName) { Console.WriteLine("length of rectangle"); var LengthOfRectangle = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("breadth of rectangle"); var BreadthOfRectangle = Convert.ToInt32(Console.ReadLine()); var AreaOfRectangle = LengthOfRectangle * BreadthOfRectangle; var perimeterOfRectangle = 2 * AreaOfRectangle; Console.WriteLine($"area is {AreaOfRectangle} and perimeter is {perimeterOfRectangle}"); Console.WriteLine((AreaOfRectangle > perimeterOfRectangle)? "area is greater than its perimeter": "area is less than its perimeter"); }
/// <summary> /// Any integer is input through the keyboard. /// Write a program to find out whether it is an odd number or even number. /// </summary> /// <param name="Chapter2"></param> public static void FindEvenAndOdNumber(this Chapter_02.ProfitAndLoss Chapter2) { Console.WriteLine("Enter the Number"); int InputNumber = Convert.ToInt32(Console.ReadLine()); if (InputNumber % 2 != 0) { Console.WriteLine("Given Number is Odd"); } else { Console.WriteLine("Given number is Even"); } }
/// <summary> /// Write a program to check whether a triangle is valid or not, /// when the three angles of the triangle are entered through the keyboard. /// A triangle is valid if the sum of all the three angles is equal to 180 degrees. /// </summary> public static void FindTheThreeAnglesOftriangel(this Chapter_02.ProfitAndLoss chapter2) { Console.WriteLine("Enter the angle of the side A"); int AngleforSideA = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the angle of the side B"); int AngleforSideB = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the angle of the side C"); int AngleforSideC = Convert.ToInt32(Console.ReadLine()); // string triangle = (AngleforSideA + AngleforSideB + AngleforSideC) == 180 ? "it is a triangle" : "it is not a Triangle"; Console.WriteLine((AngleforSideA + AngleforSideB + AngleforSideC) == 180 ? "it is a triangle" : $"it is not a Triangle as some of the angles is {AngleforSideA + AngleforSideB + AngleforSideC}"); }
/// <summary> /// Any character is entered through the keyboard, /// write a program to determine whether the character entered is /// a capital letter, 65 – 90 /// a small case letter, 97 – 122 /// a digit or 48 – 57 /// a special symbol. - 0 - 47, 58 - 64, 91 - 96, 123 - 127 /// The following table shows the range of ASCII values for various characters /// /// </summary> /// <param name="ClassName"></param> public static void CharactersASCIIValue(this Chapter_02.ProfitAndLoss ClassName) { Console.WriteLine("Enter the characters"); int inputcharacterASCII = char.Parse(Console.ReadLine()); if (65 <= inputcharacterASCII && inputcharacterASCII <= 90) { Console.WriteLine("it is a Upper Case letter"); } else if (97 <= inputcharacterASCII && inputcharacterASCII <= 122) { Console.WriteLine("it is a lower Case letter"); } else if (48 <= inputcharacterASCII && inputcharacterASCII <= 57) { Console.WriteLine("it is a Number"); } else if ((0 <= inputcharacterASCII && inputcharacterASCII <= 47) | (58 <= inputcharacterASCII && inputcharacterASCII <= 64) | (91 <= inputcharacterASCII && inputcharacterASCII <= 96) | (123 <= inputcharacterASCII && inputcharacterASCII <= 127)) { Console.WriteLine("it is a special symbol"); } else { Console.WriteLine("it is not upper or lower case Or a number "); } //else if (inputcharacterASCII >= 97 && inputcharacterASCII >= 122) //{ // Console.WriteLine("it is a lower Case letter"); //} //else if (inputcharacterASCII >= 48 && inputcharacterASCII >= 57) //{ // Console.WriteLine("it is a Number"); //} //else (inputcharacterASCII >= 0 && inputcharacterASCII >= 47 && // inputcharacterASCII >= 58 && inputcharacterASCII >= 64 && // inputcharacterASCII >= 91 && inputcharacterASCII >= 96 && // inputcharacterASCII >= 123 && inputcharacterASCII >= 127) //{ // Console.WriteLine("it is a special symbol"); //} }
/// <summary> ///If the three sides of a triangle are entered through the ///keyboard, write a program to check whether the triangle is ///valid or not. The triangle is valid if the sum of two sides is ///greater than the largest of the three sides. /// </summary> public static void FindifTriangleIsvalid(this Chapter_02.ProfitAndLoss classname) { Console.WriteLine("Enter 1 side of triangle"); Console.WriteLine("Enter Side 2"); Console.WriteLine("Enter Side 3"); int side1 = Convert.ToInt32(Console.ReadLine()); int side2 = Convert.ToInt32(Console.ReadLine()); int side3 = Convert.ToInt32(Console.ReadLine()); int largestof3Sides = (side1 > side2 && side1 > side3) ? side1 : (side2 > side1 && side2 > side3) ? side2 : side3; int SumOfSides = side1 + side2 + side3; if (SumOfSides - largestof3Sides > largestof3Sides) { Console.WriteLine("triangle is valid"); } else { Console.WriteLine("it is not a valid Triangle"); } }
/// <summary> /// Given three points (x1, y1), (x2, y2) and (x3, y3), /// write a program to check if all the three points fall on one straight line /// </summary> /// <param name="classname"></param> public static void ThreePointsFallOnOneStraightLine(this Chapter_02.ProfitAndLoss classname) { Console.WriteLine("enter x1,y1"); int x1 = Convert.ToInt32(Console.ReadLine()); int y1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("enter x2,y2"); int x2 = Convert.ToInt32(Console.ReadLine()); int y2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("enter x3,y3"); int x3 = Convert.ToInt32(Console.ReadLine()); int y3 = Convert.ToInt32(Console.ReadLine()); //(x2−x1)(y3−y1)−(y2−y1)(x3−x1) //https://math.stackexchange.com/questions/701862/how-to-find-if-the-points-fall-in-a-straight-line-or-not int collinearity = (((x2 - x1) * (y3 - y1)) - ((y2 - y1) * (x3 - x1))); Console.WriteLine(collinearity == 0? "all the three points fall on one straight line": "all the three points not fall on one straight line"); }
/// <summary> /// /// </summary> /// <param name="Classname"></param> public static void rulesforinsurence(this Chapter_02.ProfitAndLoss Classname) { Console.WriteLine("Enter Age of person"); int AgeOfperson = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Gender"); string GenderOfperson = Console.ReadLine(); Console.WriteLine("Enter AreaOfLiving"); Console.WriteLine("Person living in City then type C" + "/n" + " if Person lives in Village type V "); string personLivingin = Console.ReadLine(); string LivingAreais = (personLivingin == "c" ? "city" : "Village"); Console.WriteLine("Enter Health Condition "); Console.WriteLine("if he has Excellent Condition then type E else Type P "); string HealthConditionOfperson = Console.ReadLine(); HealthConditionOfperson = (HealthConditionOfperson == "E" ? "Excellent" : "Poor"); if (25 <= AgeOfperson & AgeOfperson <= 35) { if (LivingAreais != "city" && HealthConditionOfperson != "Excellent") { Console.WriteLine("premium is Rs. 6 per thousand and his policy cannot exceed Rs. 10,000."); } else if (GenderOfperson != "m") { Console.WriteLine(" premium is Rs. 3 per thousand and her policy amount cannot exceed Rs. 1 lakh."); } else { Console.WriteLine("premium is Rs. 4 per thousand and his policy amount cannot exceed Rs. 2 lakhs"); } } else { Console.WriteLine(" person is not insured"); } }
/// <summary> /// If the ages of Ram, Shyam and Ajay are input through the keyboard, /// write a program to determine the youngest of the three. /// </summary> public static void FindYongestOfthree(this Chapter_02.ProfitAndLoss inputClass) { Console.WriteLine("Add age of RAM"); int ageOfRam = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Add age of Shyam"); int ageOfShyam = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Add age of Ajay"); int ageOfAjay = Convert.ToInt32(Console.ReadLine()); if (ageOfRam < ageOfShyam && ageOfRam < ageOfAjay) { Console.WriteLine("Ram is Young"); } else if (ageOfShyam < ageOfRam && ageOfShyam < ageOfAjay) { Console.WriteLine("SHyam is Young "); } else { Console.WriteLine("Ajay is young "); } }
/// <summary> /// Write a program, which will require the user to give values of /// hardness, carbon content and tensile strength of the steel ///under consideration and output the grade of the steel. /// </summary> public static void FindTheGradeOfSteel(this Chapter_02.ProfitAndLoss className) { Console.WriteLine("Enter the Hardness of the Steel"); int HardnessofSteel = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Carbon Content of the steel"); float CorbonContentofSteel = float.Parse(Console.ReadLine()); Console.WriteLine("Enter Tensile strength of the steel "); int TensileStrenthofSteel = Convert.ToInt32(Console.ReadLine()); if (HardnessofSteel > 50 && CorbonContentofSteel < 0.7 && TensileStrenthofSteel > 5600) { Console.WriteLine("Grade 10 Steel"); } else if (HardnessofSteel > 50 && CorbonContentofSteel < 0.7) { Console.WriteLine("Grade 9 Steel"); } else if (CorbonContentofSteel < 0.7 && TensileStrenthofSteel > 5600) { Console.WriteLine("Grade 8 Steel"); } else if (HardnessofSteel > 50 && TensileStrenthofSteel > 5600) { Console.WriteLine("Grade 7 Steel"); } else if (HardnessofSteel < 50 || CorbonContentofSteel > 0.7 || TensileStrenthofSteel < 5600) { Console.WriteLine("Grade 6 Steel"); } else { Console.WriteLine("Grade 5 Steel"); } }