Are you sure about your entered formatting here?
The spaces are uneven for the last column and also for first 4 rows. Perhaps you tried to make them look even?
If so, in left-alignment:
Code:
#include<iostream>
using namespace std;
int main()
{
int multiplier[]={2,3,4,5};
int i, j;
cout.setf(ios::left);
for(i=1;i<11;i++)
{
for(j=0;j<4;j++)
{
cout.width(2);
cout<<multiplier[j]*i;
cout<<"|";
}
cout<<endl;
}
return 0;
}
Outputs as:
Code:
2 |3 |4 |5 |
4 |6 |8 |10|
6 |9 |12|15|
8 |12|16|20|
10|15|20|25|
12|18|24|30|
14|21|28|35|
16|24|32|40|
18|27|36|45|
20|30|40|50|
Or in right alignment:
Code:
#include<iostream>
using namespace std;
int main()
{
int multiplier[]={2,3,4,5};
int i, j;
cout.setf(ios::right);
for(i=1;i<11;i++)
{
for(j=0;j<4;j++)
{
cout.width(2);
cout<<multiplier[j]*i;
cout<<"|";
}
cout<<endl;
}
return 0;
}
Outputs as:
Code:
2| 3| 4| 5|
4| 6| 8|10|
6| 9|12|15|
8|12|16|20|
10|15|20|25|
12|18|24|30|
14|21|28|35|
16|24|32|40|
18|27|36|45|
20|30|40|50|
Right alignment with a last-column space as seen in your format (Looks unique and out of place).
Code:
#include<iostream>
using namespace std;
int main()
{
int multiplier[]={2,3,4,5};
int i, j;
cout.setf(ios::right);
for(i=1;i<11;i++)
{
for(j=0;j<4;j++)
{
cout.width(2);
cout<<multiplier[j]*i;
if(j==2)
cout<<"| ";
else
cout<<"|";
}
cout<<endl;
}
return 0;
}
Outputs as:
Code:
2| 3| 4| 5|
4| 6| 8| 10|
6| 9|12| 15|
8|12|16| 20|
10|15|20| 25|
12|18|24| 30|
14|21|28| 35|
16|24|32| 40|
18|27|36| 45|
20|30|40| 50|
Or much more neater:
P.s. Without any variables except the counters.
Code:
#include<iostream>
using namespace std;
int main()
{
cout.setf(ios::right);
for(int i=1;i<11;i++)
{
for(int j=2;j<6;j++)
{
cout.width(2);
cout<<j*i<<" | ";
}
cout<<endl;
}
return 0;
}
Outputs as:
Code:
2 | 3 | 4 | 5 |
4 | 6 | 8 | 10 |
6 | 9 | 12 | 15 |
8 | 12 | 16 | 20 |
10 | 15 | 20 | 25 |
12 | 18 | 24 | 30 |
14 | 21 | 28 | 35 |
16 | 24 | 32 | 40 |
18 | 27 | 36 | 45 |
20 | 30 | 40 | 50 |