First off this is my first post so sorry if it's a tad out of touch with how the forum works!
Anyway, I am currently trying to fill a 64 length array[n] with 1/n. But fill every odd index with 0. Oh and the first [0] index should be 1, but I have that part correctly coded (see code below).
for example, the first 5 values should be:
Square = 1
Square = 0
Square = 0.3333
Square = 0
Square = 0.2
Square = 0
Square = 0.1429
Square = 0
Square = 0.1111 .......
#include <iostream>
int main()
{
constint ARRAY_SZ = 64 ;
double array[ARRAY_SZ] = {0} ; // initialise to all zeroes
// fill elements at even positions (note: i += 2 )
for( int i = 0 ; i < ARRAY_SZ ; i += 2 ) array[i] = 1.0 / (i+1) ;
// print the contents of the array, ten numbers per line
for( int i = 0 ; i < ARRAY_SZ ; ++i )
{
std::cout << std::fixed << array[i] << " " ;
if( i%10 == 9 ) std::cout << '\n' ;
}
std::cout << '\n' ;
}