C# Tutorial
This C# program is used to find the grade for each students based on marks obtained uisng else if and for loop.
Computation Logic:
Grade is 'A' if student mark is greater than 90.
Grade is 'B' if student mark is greater than 80 and less than or equal to 90.
Grade is 'C' if mark is greater than 70 and less than or equal to 80.
Grade is 'D' if mark is greater than 50 and less than or equal to 70.
Grade is 'FAIL' if mark is less than or equal to 50.
/* This C# program to find the grade for each students. */ using System; // System is a namespace public class GradeComputation { // Main method which starts the program execution. public static void Main() { string[] studentId = { "STU01", "STU02", "STU03", "STU04", "STU05" }; int[] marks = { 76, 83, 92, 65, 34 }; Console.WriteLine("Finds the grade for each student"); for(int i=0;i<studentId.Length;i++) { if (marks[i] > 90) { Console.WriteLine(studentId[i] + " Grade: " + "A"); }else if(marks[i] > 80) { Console.WriteLine(studentId[i] + " Grade: " + "B"); } else if (marks[i] > 70) { Console.WriteLine(studentId[i] + " Grade: " + "C"); } else if (marks[i] > 50) { Console.WriteLine(studentId[i] + " Grade: " + "D"); } else { Console.WriteLine(studentId[i] + " Grade: " + "FAIL"); } } Console.ReadKey(); } }
Output:
C:> csc GradeComputation.cs C:> GradeComputation Finds the grade for each student STU01 Grade: C STU02 Grade: B STU03 Grade: A STU04 Grade: D STU05 Grade: FAIL
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page