Advertisement
BojidarDosev

Choice / 359str/11

Mar 20th, 2021
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Caaaa
  4. {
  5.     class Program
  6.     {
  7.         static int Rev(int k) //method 1
  8.         {
  9.             int k1 = 0;
  10.             while (k!=0)
  11.             {
  12.                 k1 = k1 * 10 + k % 10;
  13.                 k = k / 10;
  14.             }
  15.             return k1;
  16.  
  17.         }
  18.         static void Avg()  //2
  19.         {
  20.             Console.Write("br = ");
  21.             int br = int.Parse(Console.ReadLine());
  22.             int sum = 0;
  23.             int x;
  24.             for (int i = 0; i < br; i++)
  25.             {
  26.                 Console.Write("x -> ");
  27.                 x = int.Parse(Console.ReadLine());
  28.                 sum = sum + x;
  29.  
  30.             }
  31.             Console.WriteLine("avg = " + Math.Round(1.0 * sum / br,2));
  32.         }
  33.  
  34.         static double Eq() //3
  35.         {
  36.             Console.Write("a = "); double a = double.Parse(Console.ReadLine());
  37.             while (a == 0)
  38.             {
  39.              Console.Write("a = ");  a = double.Parse(Console.ReadLine());
  40.             }
  41.             Console.Write("b = "); double b = double.Parse(Console.ReadLine());
  42.             return Math.Round(-b / a,2);
  43.         }
  44.         static void Main(string[] args)
  45.         {
  46.             int ch;
  47.             int K;
  48.             double x;
  49.             do
  50.             {
  51.                 Console.WriteLine("1 - reverse ");
  52.                 Console.WriteLine("2 - avg ");
  53.                 Console.WriteLine("3 - eq ");
  54.                 Console.WriteLine("4 - finish ");
  55.                 Console.Write("your choice : ");
  56.                 ch = int.Parse(Console.ReadLine());
  57.                 switch (ch)
  58.                 {
  59.                     case 1: Console.Write("K = "); K = int.Parse(Console.ReadLine());
  60.                         Console.WriteLine(" k1 = " + Rev(K)); break;
  61.                     case 2: Avg(); break;
  62.                     case 3: x = Eq(); Console.WriteLine("x = " + x); break;
  63.                        
  64.                 }
  65.             } while (ch!=4);
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement