This is what I have, but I need to make a for loop instead of the initialize steep. PLEASE HELP

int main ()
{
	int numb[10];//1,2,4,8,16,32,64,128,256,512
	int numb2[10];
	int counter, counter2;


/*	
	numb[0]=1,numb[1]=2,numb[2]=4,numb[3]=8,numb[4]=16,numb[5]=32;
	numb[6]=64,numb[7]=128,numb[8]=256,numb[9]=512;
	
	numb2[0]=0,numb2[1]=1,numb2[2]=5,numb2[3]=3,numb2[4]=10,numb2[5]=5;
	numb2[6]=15,numb2[7]=7,numb2[8]=20,numb2[9]=9;
*/
	for (int z=0; z<10; z++)
			cout<<numb[z]<<" ";
	cout<<endl<<endl;


	for (int x=0; x<10; x++)
			cout<<numb2[x]<<" ";
	cout<<endl<<endl;



return 0;
}

Recommended Answers

All 4 Replies

Initializing numb is easy. Just start at 1 and double the last value until you get to the size of the array:

int k = 1;

for (int i = 0; i < 10; ++i) {
  numb[i] = k;
  k *= 2;
}

Initializing numb2 is a lot harder. Edward can't find a good pattern in the current list of numbers. Alternating between adding by 5 and dividing by 2 is close, but far enough off that I'm not sure if that's what you're looking for.

Thank you

for( int i=0 ; i<10 ; ++i )
    numb2[i] = i%2 == 0 ? (i/2)*5 : i ;

Thank You but this only helps with half

for( int i=0 ; i<10 ; ++i )
    numb2[i] = i%2 == 0 ? (i/2)*5 : i ;

the numbers should be 0,1,5,3,10,5,15,7,20,9
even positions have values 0,5,10...
odd positions have values 1,3,5...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.