Sure, here is a code example in C# that calculates the average of 5 numbers entered by the user from the keyboard:
using System; namespace AverageCalculator { class Program { static void Main(string[] args) { int sum = 0; int number; Console.WriteLine("Enter 5 numbers to calculate their average:"); for (int i = 0; i < 5; i++) { Console.Write("Enter number {0}: ", i+1); number = Convert.ToInt32(Console.ReadLine()); sum += number; } double average = (double)sum / 5; Console.WriteLine("The average of the 5 numbers is: {0}", average); } } }
You can copy and paste this code into a new C# console application project in Visual Studio and run the program to calculate the average of 5 numbers entered by the user.
Sure, here is a code example in C# that calculates the average of 5 numbers entered by the user from the keyboard:
using System;namespace AverageCalculator
{
class Program
{
static void Main(string[] args)
{
int sum = 0;
int number;
Console.WriteLine("Enter 5 numbers to calculate their average:");
for (int i = 0; i < 5; i++)
{
Console.Write("Enter number {0}: ", i+1);
number = Convert.ToInt32(Console.ReadLine());
sum += number;
}
double average = (double)sum / 5;
Console.WriteLine("The average of the 5 numbers is: {0}", average);
}
}
}
You can copy and paste this code into a new C# console application project in Visual Studio and run the program to calculate the average of 5 numbers entered by the user.