DamSi

Untitled

Mar 8th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.65 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 Lab12_3
  8. {
  9.     class Program
  10.     {   /*
  11.          ** author: Damjan Miloshevski
  12.          ** contact: [email protected];
  13.          ** skype: damjan.milosevski
  14.          ** phone: +38978566409;
  15.          ** web: https://www.facebook.com/damjan.miloshevski
  16.                  http://miloshevski.us.to/
  17.        */
  18.  
  19.         static void Main(string[] args)
  20.         {
  21.             Console.WriteLine("------ PROGRAMA ZA BROEVI. VIZUELNO PROGRAMIRANJE - LAB. 1 ------");
  22.             Console.WriteLine();
  23.             Console.WriteLine("Izberi:");
  24.             Console.WriteLine();
  25.             Console.WriteLine("1 - Vnesi rachno");
  26.             Console.WriteLine("2 - Generiraj avtomatski");
  27.             Console.WriteLine("3 - Izlezi");
  28.             Console.WriteLine();
  29.             Console.Write("Vashiot izbor e? ");
  30.  
  31.             try
  32.             {
  33.                 int input = Convert.ToInt32(Console.ReadLine());
  34.  
  35.                 switch (input)
  36.                 {
  37.                     case 1:
  38.                         {
  39.                             Console.WriteLine();
  40.                             Console.WriteLine("------ RACHNO VNESUVANJE ------ ");
  41.                             Console.WriteLine();
  42.                             Console.Write("Kolku broevi kje vnesete? ");
  43.                             int n = Convert.ToInt32(Console.ReadLine());
  44.                             int[] numbers = new int[n];
  45.                             int min;
  46.                             int max;
  47.                             double avg;
  48.                             double sum = 0;
  49.                             int i;
  50.                             Console.WriteLine();
  51.                             Console.WriteLine("Vnesete gi vashite broevi:");
  52.                             Console.WriteLine();
  53.                             for (i = 0; i < n; i++)
  54.                             {
  55.                                 Console.Write("Broj {0} = ", i + 1);
  56.                                 numbers[i] = Convert.ToInt32(Console.ReadLine());
  57.                                 sum += numbers[i];
  58.                             }
  59.                             Console.WriteLine();
  60.                             Console.WriteLine("Vashite broevi se:");
  61.                             for (i = 0; i < n; i++)
  62.                             {
  63.  
  64.                                 Console.Write("{0} ", numbers[i]);
  65.  
  66.                             }
  67.                             FindMinMax(numbers, out min, out max);
  68.                             avg = Average(numbers, sum);
  69.                             Console.WriteLine();
  70.                             Console.WriteLine();
  71.                             Console.WriteLine(string.Format("Suma = {0:#.##} | Prosek = {1:#.##} | Minimum = {2:#.##} | Maximum = {3:#.##}", sum, avg, min, max));
  72.                             Console.WriteLine();
  73.                             Console.WriteLine("Pritisnete bilo koe kopce da izlezete.");
  74.                             break;
  75.                         }
  76.                     case 2:
  77.                         {
  78.                             Console.WriteLine();
  79.                             Console.WriteLine("------ AVTOMATSKO GENERIRANJE ------ ");
  80.                             Console.WriteLine();
  81.                             Console.Write("Kolku broevi da se generiraat? ");
  82.                             int n = Convert.ToInt32(Console.ReadLine());
  83.                             int[] numbers = new int[n];
  84.                             int min;
  85.                             int max;
  86.                             double avg = 0;
  87.                             double sum = 0;
  88.                             int i;
  89.                             Random rand = new Random();
  90.                             for (i = 0; i < n; i++)
  91.                             {
  92.                                 numbers[i] = rand.Next(1, 1000);
  93.                                 sum += numbers[i];
  94.                             }
  95.                             FindMinMax(numbers, out min, out max);
  96.                             avg = Average(numbers, sum);
  97.                             Console.WriteLine();
  98.                             Console.WriteLine("Vo opseg [1,1000], vashite broevi se:");
  99.                             Console.WriteLine();
  100.                             for (i = 0; i < n; i++)
  101.                             {
  102.  
  103.                                 Console.Write("{0} ", numbers[i]);
  104.  
  105.                             }
  106.                             Console.WriteLine();
  107.                             Console.WriteLine();
  108.                             Console.WriteLine(string.Format("Suma = {0:#.##} | Prosek = {1:#.##} | Minimum = {2:#.##} | Maximum = {3:#.##}", sum, avg, min, max));
  109.                             Console.WriteLine();
  110.                             Console.WriteLine("Pritisnete bilo koe kopce da izlezete.");
  111.                             break;
  112.                         }
  113.                     case 3:
  114.                         {
  115.                             Console.WriteLine();
  116.                             Console.WriteLine("------ IZLEZ ------");
  117.                             Console.WriteLine();
  118.                             Console.WriteLine("Se otkazuvate :(. Izbravte izlez. Programata sega kje zavrshi.");
  119.                             Console.WriteLine();
  120.                             Console.WriteLine("Pritisnete bilo koe kopche da izlezete.");
  121.                             break;
  122.                         }
  123.                     default:
  124.                         Console.WriteLine("Nevaliden izbor. Programata sega kje zavrshi.");
  125.                         Console.WriteLine("Pritisnete bilo koe kopce da izlezete.");
  126.                         break;
  127.                 }
  128.             }
  129.             catch (FormatException)
  130.             {
  131.                 Console.WriteLine();
  132.                 Console.WriteLine("Pogreshen vlez. Ve molime startuvajte ja programata odnovo.");
  133.                 Console.WriteLine("Pritisnete bilo koe kopche da izlezete.");
  134.             }
  135.             Console.ReadKey();
  136.         }
  137.         public static void FindMinMax(int[] arr, out int min, out int max)
  138.         {
  139.             min = int.MaxValue;
  140.             max = int.MinValue;
  141.             for (int i = 0; i < arr.Length; i++)
  142.             {
  143.                 if (arr[i] > max)
  144.                 {
  145.                     max = arr[i];
  146.                 }
  147.                 if (arr[i] < min)
  148.                 {
  149.                     min = arr[i];
  150.                 }
  151.             }
  152.         }
  153.         public static double Average(int[] arr, double sum)
  154.         {
  155.             return sum / arr.Length;
  156.         }
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment