Nikolcho

1 задача

May 20th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 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 _01.Students
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("How many students?");
  14.             int n = int.Parse(Console.ReadLine());
  15.             double[] grades = new double[n];
  16.             int[] failed = new int[n];
  17.             int sreden = 0, good = 0, verygood = 0, excelent = 0;
  18.  
  19.             double averageGrade = 0;
  20.             int j = 0;
  21.             for (int i = 0; i < n; i++)
  22.             {
  23.                 grades[i] = double.Parse(Console.ReadLine());
  24.                 while (grades[i] < 2 || grades[i] > 6)
  25.                 {
  26.                     Console.WriteLine("Greshna ocenka. Napishi nova: ");
  27.                     grades[i] = double.Parse(Console.ReadLine());
  28.                 }
  29.                 if (grades[i] == 2)
  30.                 {
  31.                     failed[j] = i + 1;
  32.                     j++;
  33.                 }
  34.                 switch (grades[i])
  35.                 {
  36.                     case 3:
  37.                         sreden++;
  38.                         break;
  39.                     case 4:
  40.                         good++;
  41.                         break;
  42.                     case 5:
  43.                         verygood++;
  44.                         break;
  45.                     case 6:
  46.                         excelent++;
  47.                         break;
  48.                  }
  49.                 averageGrade += grades[i];
  50.             }
  51.  
  52.             averageGrade /= n;
  53.  
  54.             Console.Write("Nomera na uchenici sus slab 2: ");
  55.             for (int i = 0; i < n; i++)
  56.             {
  57.                 if (failed[i] == 0)
  58.                 {
  59.                     break;
  60.                 }
  61.                 Console.Write(failed[i] + " ");
  62.             }
  63.             Console.WriteLine();
  64.             Console.WriteLine($"Average grade is: {averageGrade:F2}");
  65.             Console.WriteLine($"Broi na uchenici s 2: {failed.Count(g => g != 0)}");
  66.             Console.WriteLine($"Broi na uchenici s 3: {sreden}");
  67.             Console.WriteLine($"Broi na uchenici s 4: {good}");
  68.             Console.WriteLine($"Broi na uchenici s 5: {verygood}");
  69.             Console.WriteLine($"Broi na uchenici s 6: {excelent}");
  70.  
  71.  
  72.  
  73.  
  74.         }
  75.     }
  76. }
Add Comment
Please, Sign In to add comment