In: Computer Science
Write in C# please! Ask the user to enter all of their exam grades. Once they are done, calculate the minimum score, the maximum score and the average score for all of their scores. Perform this using at least 2 Loops (can be the same type of loop) and not any built in functions.
Solution:
Program.cs:
using System;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
int[] marks = new int[6]; //creating an array of 6 elements
int sum = 0, min, max ;
Console.WriteLine("Enter the grades of the student: ");
for(int i =0; i< 6; i++)
{
//Reading the grades of the student
marks[i] = Convert.ToInt32(Console.ReadLine());
//Summing up the gardes to find the average
sum += marks[i];
}
max = marks[0]; //setting max and min as the first score
min = marks[0];
for (int i = 1; i < 6; i++)
{
//iterating the loop of scores to find the max and min of the
scores
if (marks[i] > max)
{
max = marks[i];
}
if (marks[i] < min)
{
min = marks[i];
}
}
Console.WriteLine("Maximum score = {0}", max);
Console.WriteLine("Minimum score = {0}", min);
Console.WriteLine("Average score = {0}", sum / 6);
Console.ReadLine();
}
}
}
Output: