Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2.  
  3. namespace minandMax
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n, p, q;
  10.  
  11.             Console.Write("n=");
  12.             n = int.Parse(Console.ReadLine());
  13.             Console.Write("p=");
  14.             p = int.Parse(Console.ReadLine());
  15.             Console.Write("q=");
  16.             q = int.Parse(Console.ReadLine());
  17.  
  18.             Random rnd = new Random();
  19.             int a = rnd.Next(p, q);
  20.  
  21.             int min = a;
  22.             int max = a;
  23.  
  24.             for(int i =0; i < n; i++)
  25.             {
  26.                 Console.Write(a + " ");
  27.                 if (min > a)
  28.                 {
  29.                     min = a;
  30.                 }
  31.                 if (max < a)
  32.                 {
  33.                     max = a;
  34.                 }
  35.                 a = rnd.Next(p, q);
  36.             }
  37.  
  38.             Console.WriteLine("Max - Min ={0}", max - min);
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement