Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

i want to write a console app that get int value from user and put them in a array

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(" |");
      

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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]);}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading