Array Intialization :)

Here I have functions that initializes first 25 elements by squaring the index and the other 25 by multiplying 3 times the index. My assignment has instructed me to print out 10 elements per array. How possibly can I print out 10 numbers per line?????

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
//Function to initlizae an array. First 25 components is equal to the square of the index
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++;
	}
}

int _tmain(int argc, _TCHAR* argv[])
{

	//Declare an array aplha of 50 compnents of type double
	double aplha[50];

	//Function call to intialize first twenty five from the square of index variable
	twentyfivecompinitial(aplha,50);
	_getch();
Print a newline at proper moments.
How though keskiverto??
I was thinking that if index =10 then use endline, but that would be less efficient and error proned for higher numbers
Last edited on
Can you guess when 0 == (index % 10) is true?
Ahh...I like that one! I'm assuming I can use this, since any multiple of ten will give you a remainder of zero :)
Can I not use multidimensional arrays?
Anyone? Anyway I can use the multidimensional array in this problem. If yes, thwn how possibly?
Of course you can, but it depends on what you actually need to achieve.
Topic archived. No new replies allowed.