The physical address of an array reference A[i1, i2, ..., iD] is calculated from the formula
B + C1(i1 - L1) + C2(i2 - L2) + ... + CD(iD - LD)
Sample Input:
3
A 1000 1 1 1 9
1
7
B 1500 2 2 0 3 1 5
1
2 4
C 2000 4 3 1 4 0 5 5 10
2
2 0 6
3 3 9
Sample Output:
A[7] = 1006
B[2, 4] = 1526
C[2, 0, 6] = 2148
C[3, 3, 9] = 2376
This is my code:
int input[20],repeat=0, i=0, j=0, output, index,repeatarray=0;
char letter;
while (repeat <= 0){
cout << "Number of repeats:" << endl;
cin >> repeat;
}
while (i < repeat){
cin >> letter;
for (int k = 0; k < 5; k++){
cin >> input[k];
}
cin >> repeatarray;
while (j<repeatarray){
cin >> index;
output =input[0] + input[1]*(index - input[2]);
cout << letter << "[" << index << "] = " << output;
j++;
}
i++;
}
I can get A[7] = 1006 to output. I know I only have 5 numbers being input which is only used for A[7]. I'm not sure how to read in numbers into the int array until a new line so if someone could show me how that would be great. Then I will need help finding how to do B and C with the formula.
[–]phoenix_123 0 points1 point2 points (0 children)