i want to write a console app that get int value from user and put them in a array and show sum of the numbers and min and max of them and then print them in the console in order
i write until this point of project but have some bugs...
Console.WriteLine("\n Please Enter the Number of your Numbers: \n");
int k = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" Please Enter Your Numbers:");
int[] myArray = new int[k];
int sum = 0;
//INPUT
for (int i = 0; i < k; i )
{
myArray[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" Number [" (i 1) "]: " myArray[i] " and Next:");
}
//DELETE DUPLICATE ELEMENTS
int[] newArray = myArray.Distinct().ToArray();
//SORT
Array.Sort(newArray);
Console.WriteLine("\n Your Sorted Numbers Without Duplicated ones: ");
foreach (int i in newArray)
{
Console.Write(" | " i);
}
Console.Write(" |");
CodePudding user response:
i think you are trying to make a program like this:
int i,n;
int[] a = new int[100];
Console.WriteLine("element numbers :");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("please entre your numbers : ", n);
for (i = 0; i < n; i )
{Console.WriteLine($"element i");
a[i] = Convert.ToInt32(Console.ReadLine());}
int sum = 0;
for (i = 0; i < n; i )
{sum = a[i];}
Console.WriteLine("sum is : {0}", sum);
int max = a[0];
int min = a[0];
for (i = 1; i < n; i )
{if (a[i] > max)
{max = a[i];}
if (a[i] < min)
{min = a[i];}}
Console.WriteLine("max is : " max);
Console.WriteLine("min is : " min);
Console.WriteLine("element numbers are: ");
for (i = 0; i < n; i )
{Console.WriteLine(a[i]);}