Well since your dealing with a stream and not a gui you can't easily "center" it on the screen, but you can pad the left side of each line with white space. Try to figure the rest out yourself, but feel free to ask if you really have trouble getting it.
@Mathhead200: Yes, what i meant is padding the left side of each line with white space where in my example, line4 touches the left side of the screen. How can I do that? I really don't have an idea.
this is my code:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{int n, i=0, j=0;
cout<<"Enter n: ";
cin>>n;
for(i=1;i<=n;i=i+1)
{for(j=1;j<=i;j=j+1)
cout<<"*";
cout<<endl;}
system("pause");
}
* (n is 1 or 0*2 + 1, pad is 3 or 4 - 1 - 0)
*** (n is 3 or 1*2 + 1, pad is 2 or 4 - 1 - 1)
***** (n is 5 or 2*2 + 1, pad is 1 or 4 - 1 - 2)
******* (n is 7 or 3*2 + 1, pad is 0 or 4 - 1 - 3)