NMDanny

תרגיל 6 C#

Dec 16th, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 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 CSSix
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double Avg;
  14.             double MaxAvg = -1;
  15.             Random Random = new Random();
  16.             double BestNumA=0,BestNumB=0;
  17.             for (int i = 1; i <= 30; ++i)
  18.             {
  19.                
  20.                 double NumA = Random.Next(0, 17);
  21.                 double NumB = Random.Next(0, 17);
  22.                 Avg= (NumA + NumB) / 2;
  23.                 if (Avg > MaxAvg)
  24.                 {
  25.                     BestNumA = NumA;
  26.                     BestNumB = NumB;
  27.                 }
  28.                 MaxAvg=Math.Max(Avg,MaxAvg);
  29.                 Console.WriteLine("{0} {1}            Average is {2}", NumA, NumB, Avg);
  30.  
  31.  
  32.             }
  33.             Console.WriteLine("The best group has the numbers of {0} and {1}, who result in the biggest average which is {2}", BestNumA, BestNumB, MaxAvg);
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment