Skip to content

Instantly share code, notes, and snippets.

@knifedge
Created July 20, 2016 07:00
Show Gist options
  • Save knifedge/c142f6ff3566fcf8ea00e64b7a1edf35 to your computer and use it in GitHub Desktop.
Save knifedge/c142f6ff3566fcf8ea00e64b7a1edf35 to your computer and use it in GitHub Desktop.
duplicate in an array of size n with numbers from 1 through n-1.
#include <stdio.h>
#define N 5
int main(){
int array[N],i,Asum=0;
int sum = (N *(N-1))/2;
printf("Enter %d integer from 1 to %d,with one duplicate:"N.N-1);
for(i=0;i<N;i++){
scanf("%d",&array[i]);
Asum = Asum+array[i];
}
printf("\nDuplicate number is : %d\n",Asum-sum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment