How to print 10 numbers on each line

So we have to include an array with a variable alpha made up of 50. the first 25 is to square the index variable and the second 25 is to times the index variable by 3 and then it needs to print out 10 of these numbers on each line and this is where I go wrong.... What am I doing wrong and thanks :)
#include<iostream>
using namespace std;
void main()
{
int c;
float alpha[50];
for(c=1; c<=25; c++)
alpha[c]= c*c;
for(c=26; c<=50; c++)
alpha[c]= 3*c;
for(c=1; c<=5; c++)
{
for(c=1; c<=10; c++)
cout<<alpha[c];
cout<<endl;
}

}
What am I doing wrong

You're printing the same ten numbers every time.
How do I not do that then? I am confused...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>
using namespace std;

int main()
{
   int alpha[50];

   for ( int i = 0; i < 50; i++ ) alpha[i] = ( i < 25 ) ? i * i : 3 * i;

   for ( int i = 0; i < 10; i++ ) cout << alpha[i] << ' ';
   cout << endl;

   for ( int i = 0; i < 10; i++ ) cout << alpha[25 + i] << ' ';
   cout << endl;
} 


I think I have not correctly understood the assignment. So here is the second variant

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>
using namespace std;

int main()
{
   int alpha[50];

   for ( int i = 0; i < 50; i++ ) alpha[i] = ( i < 25 ) ? i * i : 3 * i;

   for ( int i = 0; i < 5; i++ )
   {
      for ( int j = 10 * i ; j  < 10 * ( i + 1 ); j++ ) cout << alpha[j] << ' ';
      cout << endl;
   }
} 

Last edited on
thanks!
Topic archived. No new replies allowed.