0 comments

Write a console program to accept student of 3 subject marks they are m1, m2, and m3 and calculate 3 subjects’ total marks and average marks and display to the user? And display the result? in C Languages


1.Write a console program to accept student of 3 subject marks they are m1, m2, and m3 and calculate 3 subjects’ total marks and average marks and display to the user?  And display the result?

Answer:-

If any one subject he got <35 his result is fail.
If student got average marks>=60 First class
If student got average marks>=50 and < 60 Second class
If student got average marks >=35 and <50 3rd class
Sol:-By using if else if and switch case.
If else if :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("enter student name:");
            string sname = Console.ReadLine();
            Console.WriteLine("enter m1 marks");
            int m1 = int.Parse(Console.ReadLine());
            Console.WriteLine("enter m2 marks");
            int m2 = int.Parse(Console.ReadLine());
            Console.WriteLine("enter m3 marks");
            int m3 = int.Parse(Console.ReadLine());
            int tot = m1 + m2 + m3;
            int avg = tot / 3;
            Console.WriteLine("avg is" + avg);
            if(m1<35||m2<35||m3<35)
            {
                Console.WriteLine("student   "   + sname + "   is fail");
            }
            else if (avg >= 60)
            {
                Console.WriteLine("student    "+sname + "   having first class");
            }
            else if (50 <= avg && avg<60)
            {
                Console.WriteLine("student   "+sname + "   having second class");
            }
            else
            {
                Console.WriteLine("student    "+sname+"      having third class");

            }
            Console.ReadLine();
        }
    }
}


Switch case:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace average
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("enter student name:");
            string sname = Console.ReadLine();
            Console.WriteLine("enter m1 marks");
            int m1 = int.Parse(Console.ReadLine());
            Console.WriteLine("enter m2 marks");
            int m2 = int.Parse(Console.ReadLine());
            Console.WriteLine("enter m3 marks");
            int m3 = int.Parse(Console.ReadLine());
            int tot = m1 + m2 + m3;
            int avg = tot / 3;
            Console.WriteLine("avg is" + avg);
            switch (m1<35||m2<35||m3<35)
            {
                case true:
                    Console.WriteLine("student" + sname + " is fail");
                    break;
                case false:
                    switch(avg>=35&&avg<50)
                    {
                        case true:
                        Console.WriteLine("student "+sname+"having third class");
                            break;
                        case false:
                            switch (avg >=50&&avg< 60)
                            {
                                case true:
                                    Console.WriteLine("student"+sname+" having second class");
                                    break;
                                case false:
                                    Console.WriteLine("student"+sname+" having first class");
                                    break;
                            }
                            break;
                    }
                    break;
            }
            Console.ReadLine();
        }
    }

}

Output:-
C Language.jpg


Next
This is the most recent post.
Older Post
 
Toggle Footer
Top