Qn: Find how many same number of pairs are there in an array. அதாவது ஒரேமாதிரியான எண்களை கொண்ட ஜோடிகள் எத்தனை உள்ளன என்பதை கண்டறியவேண்டும்.
-By Srishti, Last Update On 29th June,2019 08:18 am
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main(){
int n,i,j,a[999],count=0;
//10 20 20 10 10 30 44 10 20
printf("Enter how many elements you want: ");
scanf("%d",&n);
printf("Enter all the elements: ");
for(i=0;i<n;i++){
    scanf("%d",&a[i]);
}
printf("Pairs Eligible for discount  is : ");
for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            if(a[i]==a[j] ){
                a[i]=-1;
                a[j]=-1;
                count++;
                break;
            }else if(a[i]==-1 || a[j]==-1){
            // skip revisiting the array element
                i++;
                break;
            }
        }
}
printf("%d",count);

return 0;
}
Output: Enter how many elements you want: 9
Enter all the elements: 10 20 20 10 10 30 44 10 20
Pairs Eligible for discount is : 3
//(10,10) (20,20) (10,10)

Pgcomments

Comments