Imagine that you are working in the production industry which produces leather shoe, for each pair of shoe your job is to label it using serial number given to you.
Assume that the serial number starts from 1 to 1000. But the serial number contains the repetition of the some number. Now your task is to identify the total number of repetition numbers in the serial list. Write a C program to provide the solution using array concept.
Test data:
The number of elements to be stored in the array is: 10
Enter the elements in tha array:
element 0: 1
element 1: 2
element 2: 3
element 3: 1
element 4: 4
element 5: 5
element 6: 6
element 7: 2
element 8: 5
element 9: 7
Expected output:
The count of repetition elements found in the array is: 3
#include <stdio.h>
#define N 1000
int main() {
int serials[N] = {0};
int n, i, x, cnt=0;
printf("The number of elements to be stored in the array is: ");
scanf("%d", &n);
for (i=0; i<n; i++) {
printf("element %d: ", i);
scanf("%d", &x);
serials[x-1]++;
}
for (i=0; i<N; i++) {
if (serials[i] > 1) {
cnt++;
}
}
printf("The count of repetition elements found in the array is: %d", cnt);
return 0;
}
Comments
Leave a comment