Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.25 KB | None | 0 0
  1. using System;
  2.  
  3. namespace c
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.WriteLine("**Welcome to use number operators**");
  10.             Console.WriteLine("Please select one of the operators");
  11.             Console.WriteLine("");            
  12.             int option=0;
  13.             do
  14.             {
  15.                 Console.WriteLine();
  16.                 Console.WriteLine("1.Sum, 2. Greatest common divisor, 3. Sort in descending, 4.Exit. Input 1~4:");
  17.                 option = Convert.ToInt32(Console.ReadLine());
  18.                 if (option == 1)
  19.                 {
  20.                     Console.WriteLine();
  21.                     Console.Write("Input integer numbers with \",\" ");
  22.                     string[] input = Console.ReadLine().Split(',');
  23.                     int[] input1 = Array.ConvertAll<string, int>(input, s => int.Parse(s));
  24.                     int sum = 0;
  25.                     for (int i = 0; i <= input1.GetUpperBound(0); i++)
  26.                     {
  27.                         sum = sum + input1[i];
  28.                     }
  29.                     Console.WriteLine("**Result=" + Convert.ToString(sum));
  30.                 }
  31.                 else if (option == 2)
  32.                 {
  33.                     Console.WriteLine();
  34.                     Console.Write("Input integer numbers with \",\" ");
  35.                     string[] input = Console.ReadLine().Split(',');
  36.                     int[] input1 = Array.ConvertAll<string, int>(input, s => int.Parse(s));
  37.                     Array.Sort(input1);
  38.                     int result = 1;
  39.                     int x = 0;
  40.                     bool Y = true;
  41.                     for (int i = 2; i <= input1[0];)
  42.                     {
  43.                         x = 0;
  44.                         if (input1[0] == 1)
  45.                         { break; }
  46.  
  47.                          Y= true;
  48.                         foreach (int item in input1)
  49.                         {
  50.                             if (item % i != 0)
  51.                             {
  52.                               Y = false;
  53.                             }
  54.  
  55.                         }
  56.                         if (Y == true)
  57.                         {
  58.                           foreach (int item in input1)
  59.                             {
  60.                               input1[x] = item / i;
  61.                                 x =x+1;
  62.                             }
  63.                             result =result * i;
  64.                         }
  65.                         else
  66.                         {
  67.                             result =result+1;
  68.                         }
  69.                     }
  70.                     Console.WriteLine("**Result=" +result);
  71.                 }
  72.                 else if (option == 3)
  73.                 {
  74.                     Console.WriteLine();
  75.                     Console.Write("Input integer numbers with \",\" ");
  76.                     string[] input = Console.ReadLine().Split(',');
  77.                     Array.Sort(input);
  78.                     Array.Reverse(input);
  79.                     Console.Write("**Result=" );
  80.                     foreach (string item in input)
  81.                     Console.Write(item+" ");
  82.                 }  
  83.             }
  84.             while (option != 4);
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement