פתרון מלא במדעי המחשב בגרות שאלה עם לולאה מקוננת, ...

פתרון מלא במדעי המחשב בגרות שאלה עם לולאה מקוננת, מציאת מקסימום, מציאת מינימום

השאלה:
בבניין משרדים 30 קומות. בכל קומה יש 7 משרדים ממוספרים 1-7.
א. כתבו תוכנית הקולטת את מספר העובדים בכל משרד ומחזירה את סך העובדים בכל קומה.
ב. הציגו כפלט את מספר הקומה שיש בה הכי פחות עובדים וכן את מספר העובדים בקומה זו.
ג. הציגו כפלט את מספר המשרד והקומה של המשרד שבו מספר העובדים הוא הגדול ביותר.


פתרון מלא בשפת c#:


using System;
class HelloWorld {
  static void Main() {
      
      Random rnd = new Random();
      
      int minEmployee=-1; //סעיף ב
      int minFloor=0;   //סעיף ב
      
      int maxEmployee =-1; //סעיף ג
      int maxFloor = 0; //סעיף ג
      int maxOffice =0; //סעיף ג
      
      for(int i=0; i<30;i++)
      {
    Console.WriteLine("Offices for "+(i+1)+" floor");
    int employeesInFloor=0; //סעיף א
        for(int j=0;j<7;j++)
        {
            Console.WriteLine("Enter number of employees floor "+(i+1)+" and office number "+(j+1));
            //int employees = int.Parse(Console.ReadLine());;
            int employees = rnd.Next(20,500);//for checking only
            employeesInFloor+=employees;
            
            if(minEmployee==-1 || minEmployee>employees)
            {
                minEmployee = employees;
                minFloor = (i+1);
                maxOffice = (j+1);
                
            }
            
            if(maxEmployee==-1 || maxEmployee<employees)
            {
                maxEmployee = employees;
                maxFloor = (i+1);
                
            }
        }
    Console.WriteLine("Total employees of "+(i+1)+" floor is "+employeesInFloor); // סעיף א

    
      }
      
     Console.WriteLine("The minimun employees belongs to "+ minFloor+" floor, and the quantity is "+minEmployee); // סעיף ב
     Console.WriteLine("The maximum employees belongs to "+ maxFloor+" floor, and the office numbers is "+maxOffice); // סעיף ג


  }
}