I Have 2 one dimensional arrays. One array is catalogue no.

(A) the other is quantity (D). I need to sum up all elements from the same catalogue no.

This is what I wrote:

It is clear to me my uniqueness algorithm is false. Looked up google & this forum & couldn’t come to conclusion how should I write it.Code:#include<stdio.h> #define N 6 #define K 3 int f(int A[N]); int i,k; void main() { int A[N]={4444, 1111, 2222, 1111 ,3333, 4444}; int D[N]= {1, 3, 7, 2, 8, 3}; int sum[N]={0}; for (i=0;i<N;i++) { k=f(A)+1; if (k==0) sum[i]=D[i]; else sum[k]+=D[k]; } printf("\nA sub array found in row i = %d, \n", f(A)+1); // puts("\nDid not found a sub array");// for (i=0;i<N;i++) printf("\nsum is = %d, \n", sum[i]); } int f(int A[N]) { int i, j, c=0; for (i = 0; i < N ; i++) for (j = 1 ; j < N ; j++) if (A[i] == A[j] ) c = i; return (c); }