/// <summary> /// If a four-digit number is input through the keyboard, write a /// program to obtain the sum of the first and last digit of this /// number. /// </summary> /// <param name="number"></param> public static void SumOfFirstAndLastDigitNumbers(this Chapter_01.SumOfFiveDigitNumber className) { Console.WriteLine("Enter four digit Number"); int inputnumber = Convert.ToInt32(Console.ReadLine()); var refinput = inputnumber.ToString(); var LengthofNumber = refinput.Length; if (inputnumber >= 10000) { Console.WriteLine("please enter 4 digits only "); } else { int lastDigit = inputnumber % 10; int firstDigit = inputnumber / 1000; //(LengthofNumber * 10); //while (inputnumber >= 10) //{ // inputnumber = inputnumber / 10; //} Console.WriteLine($"Sum of first and last digit of Given number : {firstDigit + lastDigit}"); } }
/// <summary> /// A cashier has currency notes of denominations 10, 50 and 100. /// If the amount to be withdrawn is input through the keyboard in hundreds, /// find the total number of currency notes of each denomination the cashier will have to give to the withdrawer. /// </summary> public static void currencynotesofdenomination(this Chapter_01.SumOfFiveDigitNumber number) { Console.WriteLine("Enter Amount to WithDraw"); int InputAmount = Convert.ToInt32(Console.ReadLine()); int Hunderednotes = InputAmount / 100; int fiftynotes = (InputAmount % 100) / 50; int Tens = (((InputAmount % 100)) % 50) / 10; int change = (((InputAmount % 100)) % 50) % 10; Console.WriteLine($"input Amount is {InputAmount} \n " + $"the notes in 100 {Hunderednotes} \n, " + $"in 50 is {fiftynotes} \n 10 {Tens} and \n change {change} "); }
/// <summary> /// In a town, the percentage of men is 52. /// The percentage of total literacy is 48. /// If total percentage of literate men is 35 of the total population, ///write a program to find the total number of illiterate men and women if the population of the town is 80,000 /// </summary> /// <param name="number"></param> public static void TotalPopulationOfTheTown(this Chapter_01.SumOfFiveDigitNumber number) { int TotalPopulationOfTheTown = 80000; int PopulationOfMen = (52 * TotalPopulationOfTheTown) / 100; int PopulationOfWomen = TotalPopulationOfTheTown - PopulationOfMen; int literatePopulation = (48 * TotalPopulationOfTheTown) / 100; int literateMen = (35 * TotalPopulationOfTheTown) / 100; int literateWomen = literatePopulation - literateMen; Console.WriteLine($"The Total population of {TotalPopulationOfTheTown} \n " + $"Total men {PopulationOfMen}, total women {PopulationOfWomen} " + $"\n Total literate Population {literatePopulation} \n" + $" literate Men {literateMen} literate women {literateWomen}"); }
/// <summary> /// If a five-digit number is input through the keyboard, /// write a program to reverse the number. /// </summary> /// <param name="number"></param> public static void ReverseOfFiveDigitNumber(this Chapter_01.SumOfFiveDigitNumber number) { 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 rev_num = 0; while (inputnumber > 0) { rev_num = rev_num * 10 + (inputnumber % 10); inputnumber = inputnumber / 10; } Console.WriteLine($"Reverse of the {refinput} is {rev_num}"); } }
/// <summary> /// /// </summary> /// <param name="number"></param> public static void Test(this Chapter_01.SumOfFiveDigitNumber number) { Console.WriteLine("Method Name: extension method"); }