if-else – if ladder statement in C#
//Program is constructed under Aryan Computers, Barshi
For
Example: Write program to accept roll no, name, class,four subjects marks and
calculate total and percentage and find grade using of if-else – if ladder
statement.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
struct
student
{
public
int rollno, mar, eng, hin, his, tot;
public
string sname, sclass;
}
class
Program
{
static
void Main(string[] args)
{
student s11 = new student();
Console.Write("Enter Roll No:");
s11.rollno = Convert.ToInt32(System.Console.ReadLine());
Console.Write("Enter Name of student:");
s11.sname =Convert.ToString(System.Console.ReadLine());
Console.Write("Enter class of student:");
s11.sclass = Convert.ToString(System.Console.ReadLine());
Console.Write("Enter Marks of Marathi:");
s11.mar = Convert.ToInt32(System.Console.ReadLine());
Console.Write("Enter Marks of English:");
s11.eng =
Convert.ToInt32(System.Console.ReadLine());
Console.Write("Enter Marks of History:");
s11.his =
Convert.ToInt32(System.Console.ReadLine());
Console.Write("Enter Marks of Hindi:");
s11.hin =
Convert.ToInt32(System.Console.ReadLine());
s11.tot = s11.mar + s11.eng +
s11.his + s11.hin;
int per=s11.tot/4;
Console.WriteLine("Roll No
is:{0}", s11.rollno);
Console.WriteLine("Name
is:{0}", s11.sname);
Console.WriteLine("Class
is:{0}", s11.sclass);
Console.WriteLine("Toal
is:{0}", s11.tot);
Console.WriteLine("Percentages
is:{0}",per);
if (per> 75)
{
Console.WriteLine("A Grade");
Console.ReadLine();
}
else if (per> 60)
{
Console.WriteLine("B Grade");
Console.ReadLine();
}
else if (per> 55)
{
Console.WriteLine("C Grade");
Console.ReadLine();
}
else if (per>= 35)
{
Console.WriteLine(" Pass");
Console.ReadLine();
}
else
{
Console.WriteLine("Fail");
Console.ReadLine();
}
}
}
}
OUTPUT:
Comments
Post a Comment