Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In this Project When I enter Duplicate Numbers at RunTime...I want to show Enter Another Number Without Duplicates.....

C#
static int Read(int[]arr)
        {
             int First = arr[0];
        int Second = arr[0];
        int third = arr[0];
            for (int i = 0; i < arr.Length; i++)
            {

                Console.Write("The Enterd "+i.ToString() +":");
                arr[i] = int.Parse(Console.ReadLine());

                if (arr[i] > First)
                {
                    First = arr[i];
                }
            }

            for (int j = 0; j < arr.Length; j++)
            {
                if (arr[j] > Second && First > arr[j])
                {
                    Second = arr[j];
                }
            }

            for (int k = 0; k < arr.Length; k++)
            {
                if (arr[k] > third && Second > arr[k])
                {
                    third = arr[k];
                }
            }

            return third;


        }

static void Main(string[] args)
        {
            int[] v = new int[5];
            Console.WriteLine(Read(v));
        }
    }
}
Posted
Updated 4-Oct-14 23:31pm
v2
Comments
George Jonsson 5-Oct-14 5:42am    
So what is your problem?
Kornfeld Eliyahu Peter 5-Oct-14 5:44am    
Based on your sample, you have to look up (search) for existing value on every input...(loop over array).
However I think you better consider using hash indexed array...

The algorithm is very simple here:
  1. Let the user insert a value.
  2. Validate the user entered value: if it already exists in the array then notify the error to the user and go to 1.
  3. Insert the user entered value in the array
  4. go to 1 until array is completely filled.
 
Share this answer
 
First of all, you did not specify your problem. Please, be more specific and provide more details next time.

Secondly, there are tons of answers on Google[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900