194k views
0 votes
In C#

Write a console application that inputs three integers from the
user and displays the sum, average, and smallest and
largest of the numbers. [Note: The average calculation in this
exercise shoul

1 Answer

3 votes

Console Application:

using System;

namespace ConsoleApp { class Program { static void Main(string[] args) { // Declare variables to store the input and output values int num1, num2, num3; int sum, average, smallest, largest;

// Prompt and read the first integer from the user

Console.Write("Enter the first integer: ");

num1 = int.Parse(Console.ReadLine());

// Prompt and read the second integer from the user

Console.Write("Enter the second integer: ");

num2 = int.Parse(Console.ReadLine());

// Prompt and read the third integer from the user

Console.Write("Enter the third integer: ");

num3 = int.Parse(Console.ReadLine());

// Calculate the sum of the three integers

sum = num1 + num2 + num3;

// Calculate the average of the three integers

average = sum / 3;

// Find the smallest of the three integers using conditional operators

smallest = num1 < num2 ? (num1 < num3 ? num1 : num3) : (num2 < num3 ? num2 : num3);

// Find the largest of the three integers using conditional operators

largest = num1 > num2 ? (num1 > num3 ? num1 : num3) : (num2 > num3 ? num2 : num3);

// Display the output values to the console

Console.WriteLine("The sum is {0}", sum);

Console.WriteLine("The average is {0}", average);

Console.WriteLine("The smallest is {0}", smallest);

Console.WriteLine("The largest is {0}", largest);

}

}

}

Hope this helps, and have a great day! =) </>

User AtiqGauri
by
8.3k points