In: Computer Science
USING C#
Design and implement a program (name it SumValue) that reads three integers (say X, Y, and Z) and prints out their values on separate lines with proper labels, followed by their average with proper label. Comment your code properly.Format the outputs following the sample runs below.
Sample run 1:
X = 7
Y = 8
Z = 10
Average = 8.333333333333334
using System;
class Program{
static void Main(string[] args){
int val1, val2, val3;
int total=0;
//reading 3 numbers from the console
Console.WriteLine("Please enter 3 numbers");
val1 = Convert.ToInt32(Console.ReadLine());
val2 = Convert.ToInt32(Console.ReadLine());
val3 = Convert.ToInt32(Console.ReadLine());
//adding 3 numbers and storing into total variable
total=val1+val2+val3;
//finding average by dividing with 3
double avg=total/3.0;
//printing values
Console.WriteLine("Value 1: "+val1);
Console.WriteLine("Value 2: "+val2);
Console.WriteLine("Value 3: "+val3);
Console.WriteLine("Average: "+avg);
}
}