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:
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);
}
}
}
Comments
Leave a comment