Saturday, December 5, 2009

Given an array of n integers from 1 to n with one integer repeated

#include
#include
#include

int i,j=0,k,a1[10];

main()
{
     printf("Enter the array of numbers between 1 and 100(you can repeat the numbers):");
     for(i=0;i<=9;i++)
     {
         scanf("%d",&a1[i]);
     }
    
     while(j<10)
     {
        for(k=0;k<10;k++)
        {
            if(a1[j]==a1[k] && j!=k)
            {
                printf("Duplicate found!");
                printf("The duplicate is %d\n",a1[j]);
                getch();
            }
        }
        j=j+1;
    }
   
    getch();
    return(0);
}

No comments:

Post a Comment