Task is:
- There are 2 arrays
A(numeric floating type) andBis a character array. A is populated with random numbers. - Let
A[i]denote the ith value which is associated with the ith character from B array.That is, every unique Ai is mapped /associated with a unique Bi. So,if there are similar Ai’s then each one of them would be associated with the same character from B sequentially. - Now, there is a new array which
New_Awhich is populated by random numbers which may be slightly different from that of A or few numbers may be exactly the same. The task is to create a character array New_B based on the following assumption : - We find the smallest Euclidean distance or any measure between
New_A[j]andA[i]such that given aNew_A[j], the character from B is assigned whereA[i] >=New_A[j](New_A[i] >= A[j]). Letsmall_Adenote the index j of the smallestA[j]for which the condition holds. - For ex, say the character associated with A[2] is ‘d’ and value at A[2]=12.1 and value at New_A[7]=11.9. Because, A[2]> New_A[7],New_A[7] gets mapped/associated with the character which was initially associated with A[2] which is character ‘d’ ; the rest where this condition does not hold remain unchanged. Therefore,the overall effect/objective is to create a variation of the character array B into a new character array New_B according to New_A and A.
Now,this is where I am stuck. How to find the smallest Euclidean value and then how to assign the characters of B following the condition. Moreover,the data types of the arrays are different so how would the association be done. Usage of 2D arrays was a pure guess work and there is no guarantee that I am correct.
float A[10];
char B[10] = {'c','d','e','f','g','h','i','j','k','l'} ;
for (i = 1; i <= 10; i++) {
Val_A[i] = rand();
Val_New[i] = rand();
A[i] = Val_A[i];
New_A[i][j] = Val_New[i];
}
max1 = New_A[0];
index1 = 0;
for (i = 1; i < 10; i++) {
if (A[i] > max1)
extract_char = B[i];
New_A[i][j] = extract_char;
//assigning corresponding character to New_A, which was assigned earlier to A
index1 = i;
}
First of all euclidean distance for scalars is just a fancy way of saying “absolute value of the difference” e.g. fabs(a-b)
For each element “i” in New_A:
First step 1:
This gets you the index (for A and B) that has the smallest euclidean distance.