Best Answer - Chosen by Voters
See my code below for a C++ solution to the problem. Only one 'for' loop is needed, if you take advantage of what iomanip can do for you. If you consider the spaces between the lines as contributing a unit of length, then it's an equilateral triangle. Otherwise, it's isosceles.
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
int n;
const char star('*');
const char space(' ');
if ((argc < 2) || (sscanf(argv[1],"%d",&n) != 1)) {
cout << "usage : " << argv[0] << " <n>" << endl;
cout << " where n is an integer" << endl;
return -1;
}
n = abs(n);
for (int i = 0; i < n; i++) {
cout << setfill(space) << setw(n-i) << space;
cout << setfill(star) << setw(i*2+1) << star << endl;
}
return 0;
}