Making output nicer
Is there a way I can make my output more even? Each number under its own row side by side.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include<iostream>
using namespace std;
void Powerof(int x)
{
int pwr_2=1, pwr_3=1;
//Power of 2
// -------------------------------------------
for(int i=1; i<=2; i++) {
pwr_2 = pwr_2 * x;
}
//-----------------------------------------
cout.width(20);
cout<<pwr_2<<"\n";
//Power of 3
//-----------------------------------------
for(int j=1; j<=3; j++) {
pwr_3 = pwr_3 * x;
}
//-----------------------------------------
cout.width(50);
cout<<pwr_3<<"\n";
}
int main()
{
int start_num, end_num;
cout<<"Enter starting number: ";
cin>>start_num;
cout<<"Enter ending number: ";
cin>>end_num;
cout<<"\n\n";
cout<<"X";
cout.width(20);
cout<<"X^2";
cout.width(30);
cout<<"X^3";
cout<<"\n";
for(int k=start_num; k<=end_num; k++) {
cout<<"\n"<<k<<"\n";
Powerof(k);
}
return 0;
}
|
Yes you can do that by removing most of the newlines "\n". You only want one at the end of the line.
Topic archived. No new replies allowed.