-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathduplicatecount.c
44 lines (36 loc) · 880 Bytes
/
duplicatecount.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<stdio.h>
#include<stdlib.h>
//Main Function
int main(){
int i,limit,count=0,j;
//Pointer 'ptr' has base address of array
int *ptr;
//Limit of Array
printf("Enter the Range of Array :\n");
scanf("%d",&limit);
//Memory Allocation using Malloc
ptr=malloc(sizeof(int)*limit);
//Input : Elements
printf("Enter %d Elements \n",limit);
for(i=0;i<limit;i++){
scanf("%d",&ptr[i]);
}
//Processing : Finding Count Of Duplicates
printf("\nElements\n");
for(i=0;i<limit;i++){
for(j=i+1;j<limit;j++){
if(ptr[i]==ptr[j]){
count++;
if(ptr[j]==ptr[j+
1]){
count--;
i++;
}
}
}
}
//Output Display
printf("Count Of Duplicates is %d\n",count);
return 0;
return 0;
}