Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             first();
  14.             second();
  15.             third();
  16.         }
  17.         public static void first()
  18.         {
  19.             char g;
  20.             int num = 1;
  21.             int sum = 0;
  22.             Console.WriteLine("click A to Add all numbers and hit 0 to stop");
  23.             Console.WriteLine("click F to request a fibonacci numbers");
  24.             Console.WriteLine("click R to request a random number between a given interval");
  25.             switch (g = char.Parse(Console.ReadLine()))
  26.             {
  27.                 case 'A':
  28.                     while (num != 0)
  29.                     {
  30.                         Console.WriteLine("please enter a number");
  31.                         num = int.Parse(Console.ReadLine());
  32.                         if (num == 0)
  33.                             Console.WriteLine(sum);
  34.                         else
  35.                             sum += num;
  36.  
  37.                     }
  38.                     break;
  39.                 case 'F':
  40.                     int a = 0, b = 1, c;
  41.                     Console.WriteLine("please enter the numbers of fibonacci");
  42.                     int s = num = int.Parse(Console.ReadLine());
  43.                     //display the first two elements of fibonacci
  44.                     Console.WriteLine(a);
  45.                     Console.WriteLine(b);
  46.                     for (int i = 0; i < s; i++)
  47.                     {
  48.                         c = a + b;
  49.                         Console.WriteLine(c);
  50.                         a = b;
  51.                         b = c;
  52.  
  53.                     }
  54.                     break;
  55.                 case 'R':
  56.                     Console.WriteLine("please enter the first interval");
  57.                     int x = int.Parse(Console.ReadLine());
  58.                     Console.WriteLine("please enter the second interval");
  59.                     int y = int.Parse(Console.ReadLine());
  60.                     Random rnd = new Random();
  61.                     int z = rnd.Next(x, y);
  62.                     Console.WriteLine("the random number is " + z);
  63.  
  64.                     break;
  65.  
  66.             }
  67.             Console.ReadLine();
  68.  
  69.         }
  70.         public static void second()
  71.         {
  72.  
  73.             int num = 1, sum = 0, i = 0, max = 0, ave = 0;
  74.  
  75.             Console.WriteLine("please enter number and hit 0 to stop,");
  76.             while (num != 0)
  77.             {
  78.  
  79.                 Console.WriteLine("enter a number");
  80.                 num = int.Parse(Console.ReadLine());
  81.  
  82.                 i++;
  83.                 if (num > max) max = num;
  84.                 sum += num;
  85.                 ave = sum / i+1;
  86.  
  87.  
  88.             }
  89.             char g;
  90.             Console.WriteLine("click A to get average");
  91.             Console.WriteLine("click B to get the max value");
  92.             switch (g = char.Parse(Console.ReadLine()))
  93.             {
  94.                 case 'A':
  95.                     Console.WriteLine(ave);
  96.                    
  97.                     break;
  98.                 case 'B':
  99.                     Console.WriteLine(max);
  100.                     break;
  101.             }
  102.             Console.ReadLine();
  103.         }
  104.         public static void third()
  105.         {
  106.             Console.WriteLine("please enter your height");
  107.             double a = double.Parse(Console.ReadLine());
  108.             Console.WriteLine("please enter your weight");
  109.             double b = double.Parse(Console.ReadLine());
  110.            double BMI = b / (a * a);
  111.            Console.WriteLine("your BMI is "+BMI);
  112.            if (BMI <18.5 || BMI> 25)
  113.            {
  114.                Console.WriteLine("its bad");
  115.            }
  116.            else
  117.            {
  118.                Console.WriteLine("its good");
  119.            }
  120.            Console.ReadLine();
  121.         }
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement