وعليكم السلام ورحمة الله.
مرفق طريقتين للحل واحدة باستخدام المصفوفات Arrays وواحدة باستخدام Lists
طريقة المصفوفة
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int[] numbers = new int[10];
int option = 0;
for (int i = 0; i < 10; i++)
{
Console.Write("Enter number " + (i + 1) + ": ");
numbers[i] = int.Parse(Console.ReadLine());
}
do
{
Console.WriteLine();
Console.WriteLine("Choose what you want to do:");
Console.WriteLine(" 1. Show the largest number");
Console.WriteLine(" 2. Show the smallest number");
Console.WriteLine(" 3. Show the mean to one decimal");
Console.WriteLine(" 4. Display all input numbers");
Console.WriteLine(" 5. Finish this program");
option = int.Parse(Console.ReadLine());
if (option == 1)
{
int max = numbers[0];
for (int i = 0; i < 10; i++)
{
if (numbers[i] > max)
max = numbers[i];
}
Console.WriteLine("Max = " + max);
}
else if (option == 2)
{
int min = numbers[0];
for (int i = 0; i < 10; i++)
{
if (numbers[i] < min)
min = numbers[i];
}
Console.WriteLine("Min = " + min);
}
else if (option == 3)
{
int sum = 0;
int count = 10;
double average;
for (int i = 0; i < 10; i++)
{
sum += numbers[i];
}
average = sum / count;
Console.WriteLine("Average = " + average);
}
else if (option == 4)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(numbers[i]);
}
}
} while (option != 5);
}
}
}
طريقة List
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
List<int> numbers = new List<int>();
int option = 0;
for (int i = 0; i < 10; i++)
{
Console.Write("Enter number " + (i + 1) + ": ");
numbers.Add(int.Parse(Console.ReadLine()));
}
do
{
Console.WriteLine();
Console.WriteLine("Choose what you want to do:");
Console.WriteLine(" 1. Show the largest number");
Console.WriteLine(" 2. Show the smallest number");
Console.WriteLine(" 3. Show the mean to one decimal");
Console.WriteLine(" 4. Display all input numbers");
Console.WriteLine(" 5. Finish this program");
option = int.Parse(Console.ReadLine());
if (option == 1)
{
Console.WriteLine("Max = " + numbers.Max());
}
else if (option == 2)
{
Console.WriteLine("Min = " + numbers.Min());
}
else if (option == 3)
{
Console.WriteLine("Average = " + numbers.Average());
}
else if (option == 4)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(numbers[i]);
}
}
} while (option != 5);
}
}
}
بالتوفيق،،،