Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace c
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("**Welcome to use number operators**");
- Console.WriteLine("Please select one of the operators");
- Console.WriteLine("");
- int option=0;
- do
- {
- Console.WriteLine();
- Console.WriteLine("1.Sum, 2. Greatest common divisor, 3. Sort in descending, 4.Exit. Input 1~4:");
- option = Convert.ToInt32(Console.ReadLine());
- if (option == 1)
- {
- Console.WriteLine();
- Console.Write("Input integer numbers with \",\" ");
- string[] input = Console.ReadLine().Split(',');
- int[] input1 = Array.ConvertAll<string, int>(input, s => int.Parse(s));
- int sum = 0;
- for (int i = 0; i <= input1.GetUpperBound(0); i++)
- {
- sum = sum + input1[i];
- }
- Console.WriteLine("**Result=" + Convert.ToString(sum));
- }
- else if (option == 2)
- {
- Console.WriteLine();
- Console.Write("Input integer numbers with \",\" ");
- string[] input = Console.ReadLine().Split(',');
- int[] input1 = Array.ConvertAll<string, int>(input, s => int.Parse(s));
- Array.Sort(input1);
- int result = 1;
- int x = 0;
- bool Y = true;
- for (int i = 2; i <= input1[0];)
- {
- x = 0;
- if (input1[0] == 1)
- { break; }
- Y= true;
- foreach (int item in input1)
- {
- if (item % i != 0)
- {
- Y = false;
- }
- }
- if (Y == true)
- {
- foreach (int item in input1)
- {
- input1[x] = item / i;
- x =x+1;
- }
- result =result * i;
- }
- else
- {
- result =result+1;
- }
- }
- Console.WriteLine("**Result=" +result);
- }
- else if (option == 3)
- {
- Console.WriteLine();
- Console.Write("Input integer numbers with \",\" ");
- string[] input = Console.ReadLine().Split(',');
- Array.Sort(input);
- Array.Reverse(input);
- Console.Write("**Result=" );
- foreach (string item in input)
- Console.Write(item+" ");
- }
- }
- while (option != 4);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement