The Program in C# Program to Calculate Percentage,Division Reading roll no,name & marks is given below:
using System;
namespace StudentResult
{
class Program
{
static void Main(string[] args)
{
int rollNo;
string name;
float subject1, subject2, subject3, total, percentage;
string division;
Console.WriteLine("Hello Codeauri Family,enter the roll number here:");
rollNo = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the name:");
name = Console.ReadLine();
Console.WriteLine("Enter the marks of three subjects:");
subject1 = Convert.ToSingle(Console.ReadLine());
subject2 = Convert.ToSingle(Console.ReadLine());
subject3 = Convert.ToSingle(Console.ReadLine());
// Calculate the total marks
total = subject1 + subject2 + subject3;
// Calculate the percentage
percentage = (total / 300) * 100;
// Check the division
if (percentage >= 60)
{
division = "First";
}
else if (percentage >= 50)
{
division = "Second";
}
else if (percentage >= 40)
{
division = "Third";
}
else
{
division = "Fail";
}
Console.WriteLine("Roll No: " + rollNo);
Console.WriteLine("Name: " + name);
Console.WriteLine("Total Marks: " + total);
Console.WriteLine("Percentage: " + percentage + "%");
Console.WriteLine("Division: " + division);
}
}
}
Output:
Hello Codeauri Family,enter the roll number here:
7
Enter the name:
Joseph
Enter the marks of three subjects:
89
90
98
Roll No: 7
Name: Joseph
Total Marks: 277
Percentage: 92.33334%
Division: First
Pro-Tips💡
Here are the step by step execution of above program:
- A namespace named “StudentResult” is declared which contains the code for the program.
- In the namespace, there is a class named “Program” which has a Main method as the entry point of the program.
- Inside the Main method, various variables are declared to store the roll number, name, marks of three subjects, total marks, percentage, and division of the student.
- The program then takes input from the user for the roll number, name, and marks of three subjects using the Console.ReadLine method.
- The total marks are calculated by adding up the marks of three subjects.
- The percentage is calculated by dividing the total marks by 300 and multiplying by 100.
- An if-else statement is used to determine the division of the student based on their percentage.
- The result of the student is then displayed on the console using Console.WriteLine method, including the roll number, name, total marks, percentage, and division.
- The program ends when all the statements in the Main method are executed.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.