Answer to Question #301131 in C# for Kun

Question #301131

Write a program that declares four integers. Your program should request the user to enter the values of the 4 variables (one by one) and then the sum and average of these values must be calculated and displayed.

Your running program could resemble the following:


1
Expert's answer
2022-02-22T07:32:41-0500
using System;

namespace test
{
    class Program
    {
        public static void Main(string[] args)
        {
            int num1, num2, num3, num4, sum, avg;
            
            Console.Write("Enter value N1: ");
             num1 = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter value N2: ");
             num2 = Convert.ToInt32(Console.ReadLine());
             Console.Write("Enter value N3: ");
             num3 = Convert.ToInt32(Console.ReadLine());
             Console.Write("Enter value N4: ");
             num4 = Convert.ToInt32(Console.ReadLine());
             sum = num1+num2+num3+num4;
             Console.WriteLine();
             Console.WriteLine("Sum = {0}", sum);
             avg = sum / 4;
             Console.WriteLine();
             Console.WriteLine("Average = {0}", avg);
             
            Console.WriteLine();
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
            
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS