Jan 2, 2020 at 9:28pm UTC
I want to multiply all the elements of an array a1[120] with an array a2[90] and to store those results in another array.
Someone has an idea?
Jan 2, 2020 at 9:34pm UTC
Clarify, please.
Do you want to multiply EACH element of a1 by EACH element of a2, so producing an array of 120x90 elements?
Or what?
Some context ... and some code ... would help.
It seems a slightly strange thing to do.
Jan 2, 2020 at 10:07pm UTC
I want to calculate the area of all posible football fields, being 90 the minimum and 120 the max of the length and 45 the minimum and 90 the max of the width. I want to know all the posible fields that can be made with each of those numbers. And I thought the simpliest way to store and to multiply the values is using an array
Jan 2, 2020 at 10:53pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// Example program
#include <iostream>
using std::cout;
int main()
{
const int MinLength = 90;
const int MaxLength = 120;
const int MinWidth = 45;
const int MaxWidth = 90;
for (int length = MinLength; length <= MaxLength; length++)
{
for (int width = MinWidth; width <= MaxWidth; width++)
{
int area = length * width;
cout << length << "x" << width << " = " << area << '\n' ;
}
}
}
If you don't want duplicates, a set would be needed (or, there's probably a clever mathematical way to eliminate results).
If you want to store the results, then sure, make an array of (MaxLength - MinLength + 1) * (MaxWidth - MinWidth + 1) size.
See also:
https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem
Last edited on Jan 2, 2020 at 10:56pm UTC