Just learnt about arrays today so I'm not very good at them. But I have a practice question where it asks me:
First, declare an array of 50 integers.
Set the first value in the array (i.e. the value at offset 0) to 0.
Next, set each array element at offset x to be equal to the value of log(x). Note: in this step, we start with x = 1 (i.e., we leave the zero from step 2). Don't do this the long way - use a loop!
Finally, go through the array again. For each array element, look at the value stored and display that number of spaces (" "). At the end of the row of spaces, display a single '*' character, followed by an end-line.
It may be that it's very late right now while I'm trying to do this or I'm just being stupid about it but I'm unsure what they're trying to get me to program in step 3 and 4. I did 1 and 2 but i'm not sure what to do for 3 and 4. Thanks for your help, it is appreciated.
This is what I did so far and I'm unsure if I'm on the right path so any help would be great, thanks! :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int integerArray[50];
integerArray[0] = 0;
for (int x = 1; x <= 50; x++) {
integerArray[50] = log(x);
cout << x << endl;
}
return 0;
}
|