Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class ManyInOne
- {
- //Reverse Method
- static string Reverse(decimal number)
- {
- string newNum = "";
- string temp = number.ToString();
- for (int i = temp.Length - 1; i >= 0; i--)
- {
- newNum += temp[i] + "";
- }
- return newNum;
- }
- //Calculates Average
- static decimal AverageCalculates(decimal[] arr)
- {
- decimal sum = 0m;
- decimal average = 0m;
- foreach (int number in arr)
- {
- sum += number;
- }
- average += (sum / arr.Length);
- return average;
- }
- //Calculatesa linear equation
- static float LinearEquation(float a, float b)
- {
- float linear = 0f;
- if (a == 0)
- {
- Console.WriteLine("error");
- }
- if (a != 0)
- {
- linear = (-b) / a;
- }
- return linear;
- }
- //Filling the array
- static void FillTheArray(decimal[] arr)
- {
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i] = int.Parse(Console.ReadLine());
- }
- }
- static void Main()
- {
- Console.WriteLine("What would you like to do:");
- Console.WriteLine("1. Reverse digits of a number.");
- Console.WriteLine("2. Calculates the average of a sequence of integers.");
- Console.WriteLine("3. Solves a linear equation a * x + b = 0.");
- Console.Write("Enter the number of task you chose: ");
- byte choose = byte.Parse(Console.ReadLine());
- switch(choose)
- {
- case 1:
- Console.WriteLine("Enter a number to reverse it's digits:");
- decimal number = decimal.Parse(Console.ReadLine());
- string reverseNum = Reverse(number);
- Console.WriteLine(reverseNum);
- break;
- case 2:
- Console.WriteLine("How many numbers you want to be in your sequence: ");
- int count = int.Parse(Console.ReadLine());
- decimal[] sequence = new decimal[count];
- FillTheArray(sequence);
- decimal average = AverageCalculates(sequence);
- Console.WriteLine("The average of your numbers is {0}", average);
- break;
- case 3:
- Console.WriteLine("Enter two numbers:");
- float a = float.Parse(Console.ReadLine());
- float b = float.Parse(Console.ReadLine());
- float result = LinearEquation(a, b);
- Console.WriteLine("The result is {0}", result);
- break;
- default:
- Console.WriteLine("Wrong Enter!");
- break;
- }
- Main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement