CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 18

Threaded View

  1. #1
    Join Date
    Oct 2007
    Posts
    7

    Smile help needed to sort the array for maximum and minimum values to be found

    hi i want to sort this array using c# to find maximum and minimum values from the 10 numbers entered.
    Code:
                int[] marks = new int [9];
                
                int max=0;
                int min=0;
                int x;
                int y;
                
                Console.WriteLine("enter the marks of ten students and i will tell u which is maximum and minimum");
    
    
    
                for (x = 0; x < marks.Length; x++)
                {
    
    
                    marks[x] = Convert.ToInt32(Console.ReadLine());
    
    
                    //min = marks[0];
                }
    
    
                for (y = 0; y < marks.Length; y++)
                {
                    //here if starting no is greater than ending no than it will display the lowest and highest no
    
                    if (min<marks[0])
                    {
                        min = marks[0];
    
    
    
                        Console.WriteLine("{0} is the minimum", min);
                        Console.ReadLine();
                    }
    
                    else if (min>marks[1])
                    {
                        max = marks[1];
                        Console.WriteLine("{0} is the maximum", max);
    
                        Console.ReadLine();
    
                    }
                
    
    
    
    
                    //}
    
                    // Console.WriteLine("the highest is {0} and the lowest is {1}", marks,min);
                }
    Last edited by cjard; November 8th, 2007 at 10:55 AM. Reason: learn how to use CODE tags please

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured