Write a program in c to calculate number of duplicate entries in array
Answers
Answer:
printf("\n Please Enter Number of elements in an array : "); scanf("%d", &Size); Below For loop will help to iterate each and every cell present in the arr[5] array. Condition inside the for loops (i < Size) will ensure the compiler, not to exceed the array limit. The condition (0 < 5) is True.
Answer:
/* C Program to Count Total Duplicate Elements in an Array */
#include <stdio.h>
int main()
{
int arr[10], i, j, Size, Count = 0;
printf("\n Please Enter Number of elements in an array : ");
scanf("%d", &Size);
printf("\n Please Enter %d elements of an Array : ", Size);
for (i = 0; i < Size; i++)
{
scanf("%d", &arr[i]);
}
for (i = 0; i < Size; i++)
{
for(j = i + 1; j < Size; j++)
{
if(arr[i] == arr[j])
{
Count++;
break;
}
}
}
printf("\n Total Number of Duplicate Elements in this Array = %d ", Count);
return 0;
}