Advertisement
AvengersAssemble

P65Ex14

Dec 18th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int n = 40, max = 0, current, maxIndex = 0, count = 0, j, sum = 0;
  13.             int[,] arr = new int[n, 30];
  14.             for (int i = 0; i < arr.GetLength(0); i++)
  15.             {
  16.                 for (int k = 0; k < arr.GetLength(1); k++)
  17.                 {
  18.                     arr[i, k] = int.Parse(Console.ReadLine());
  19.                 }
  20.             }
  21.             for (int i = 0; i < arr.GetLength(1); i++)
  22.             {
  23.                 current = 0;
  24.                 for (int k = 0; k < arr.GetLength(0); k++)
  25.                 {
  26.                     arr[k, i] = int.Parse(Console.ReadLine());
  27.                     current += arr[k, i];
  28.                 }
  29.                 if (current > max)
  30.                 {
  31.                     maxIndex = i;
  32.                     max = current;
  33.                 }
  34.             }
  35.             Console.WriteLine("Best selling: " + maxIndex + 1);
  36.             for (int i = 0; i < arr.GetLength(0); i++)
  37.             {
  38.                 j = 0;
  39.                 while (j < arr.GetLength(1) && arr[i, j] != 0)
  40.                     j++;
  41.                 if (j == arr.GetLength(1))
  42.                     count++;
  43.             }
  44.             Console.WriteLine("Teenagers who own all 30 discs: " + count);
  45.             for (int i = 0; i < arr.GetLength(0); i++)
  46.             {
  47.                 for (j = 0; j < arr.GetLength(1); j++)
  48.                     sum += arr[i, j];
  49.             }
  50.             Console.WriteLine("Average amount of discs per teen: " + (double)sum / arr.GetLength(0));
  51.             // ד - כן
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement