Sunday, 1 January 2017

How to Calculate Percentage of Total Marks obtained[C#]

Write a program in C# that accepts the marks of 5 subjects and finds the sum and percentage marks obtained by the student.

Following is the simple C# code :

class Lab
        static void Main(string[] args)
            int sum=0, total = 500;
            float per;

            Console.Write("\nEnter marks of 5 subjects with comma seprated : ");
            var smarkes = Console.ReadLine();
            var arrymarkes = smarkes.Split(',');
            for (int i = 0; i < arrymarkes.Length; i++)
                sum+= Convert.ToInt32(arrymarkes[i]);
            per = (sum * 100) / total;
            Console.WriteLine("The sum of markes: "+sum);
            Console.WriteLine("\nPercentage: "+per);

No comments:

Post a Comment

Note: only a member of this blog may post a comment.