want to initialize the first 25 compmenets to (power of index) and the rest 25 to (3*index). Is there another better mehod to use or a shorter method??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void twentyfivecompinitial(double alpha[],int size)
{
int index=0;
for (index=0;index<size/2;index++)
{
alpha[index]=(index*index);
cout<<" ";
cout<<alpha[index];
}
while (index<size)
{
alpha[index]=(3*index);
cout<< " ";
cout<<alpha[index];
index++;
}
}
Raise to the power of index? You mean alpha ^ index? This can be done with pow(x,y) which is in the library <cmath>. pow(x,y) where x is the number and y is the power raised to. You will need to include a library that allows you to use very large numbers for this though, such as boost multiprecision: http://www.boost.org/doc/libs/1_53_0/libs/multiprecision/doc/html/boost_multiprecision/intro.html
If that's not what you mean and you want the first 25 to be 2x index and the next 25 to be 3x index, then your method is ok.