With your current algorithm the best solution would be to add a line counter that will determine the number of spaces. At the 0th line you print no spaces and for every newline you print, the counter gets incremented by one and you print that many spaces.
Code:
cnt = 0, i = 5: *****
cnt = 1, i = 3: ***
cnt = 2, i = 1: *
Code:
#include<iomanip.h>
#include<stdlib.h>
main()
{
int i, j, k, cnt=0; char star='*';
for(i=5;i>=1;i=i-2) {
for(k=0;k<cnt;k++)
cout<<" ";
for(j=1;j<=i;j++)
cout<<star;
cout<<endl;
cnt++;
}
return 0;
}
-Prelude