Create a 1D array storing marks of 5 students. Let the marks be 92, 83, 54, 32, 89. Calculate the sum of all the marks, find the highest and the lowest student marks and also calculate the average marks.
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace question36599
{
class Program
{
static void Main(string[] args)
{
//creating an array with marks
int[] studentMarks = new int[] {92, 83, 54, 32, 89};
int sum = 0, min = studentMarks[0], max = studentMarks[0];
double average;
//counting the sum of all the marks
for (int i = 0; i < 5; i++)
sum += studentMarks[i];
//finding the lowest mark
for (int i = 1; i < 5; i++)
if (min > studentMarks[i]) min = studentMarks[i];
//finding the highest mark
for (int i = 1; i < 5; i++)
if (max < studentMarks[i]) max = studentMarks[i];
//counting the average mark
average = sum / 5;
//output of results
Console.WriteLine("The sum of all the marks: " + sum.ToString());
Console.WriteLine("The lowest mark: " + min.ToString());
Console.WriteLine("The highest mark: " + max.ToString());
Console.WriteLine("The average mark: " + average.ToString());
}
}
}Answer:
The sum of all the marks: 350
The lowest mark: 32
The highest mark: 92
The average mark: 70
Comments