Back to Browse

Multidimensional Array C# Programming

4.1K views
Nov 2, 2020
6:48

Like, Share, And Subscribe | Professor Saad Yousuf Watch Our All Videos On This : http://www.youtube.com/ProfessorSaad Subscribe Our Channel : http://www.youtube.com/ProfessorSaad Playlists: https://www.youtube.com/user/ssby79/playlists Multidimensional Array C# Programming CODE ------------ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MultiDimArray { using static System.Console; class Program { static void Main(string[] args) { //2 dimensional array 5 rows and 4 values per row double[,] scores = { { 30, 60, 100, 100 }, //row 1 with 4 values { 100, 80, 100, 100 }, //row 2 with 4 values { 90, 90, 90, 100 }, //row 3 with 4 values { 88, 70, 96, 96 }, //row 4 with 4 values { 76, 95, 86, 97 } //row 5 with 4 values }; //parallel arrays to row dimension of two dimensional array string[] names = { "Jason", "Mary", "Kaysie", "Mark", "Jack" }; double[] sums = new double[5]; //indexes 0 to 4 //row indexes 0 through 4, column indexes 0 through 3 //to display 3rd score of student #3 //scores[2,2] //to display 1st score of student #3 //scores[2,0] //nested loop //outer loop for rows //inner loop for columns in each row for(int row=0;row<=4;row++) { WriteLine("Student name: " + names[row]); for(int col = 0; col <= 3; col++) { WriteLine("Score #" + (col+1) + " = " + scores[row, col]); //sums[row] = sums[row] + scores[row, col]; sums[row] += scores[row, col]; } WriteLine(); } //to display each student's name with their average score for (int row = 0; row <= 4; row++) { double avg = sums[row] / 4; WriteLine("Student name: " + names[row]); WriteLine("Student average score: " + avg); if (avg >= 90 && avg <= 100) WriteLine("Student letter Grade: A"); else if (avg>= 80) WriteLine("Student letter Grade: B"); else if (avg>= 70) WriteLine("Student letter Grade: C"); else if (avg>= 60) WriteLine("Student letter Grade: D"); else WriteLine("Student letter Grade: F"); } Read(); //to hold screen output } } }

Download

0 formats

No download links available.

Multidimensional Array C# Programming | NatokHD