Find duplicate number 1 to 100.

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

Here is the simplest of C programs (kind of dumb)

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

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);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s