Wednesday, March 10, 2010

this code doesn't work 100%, for even nums but add some rounding in and it will

#include "stdafx.h"
#include
using namespace std;

int main()
{
int height;
cin >> height;
int rows = height;
int cols = height*2 - 1;
   for (int r = 1; r <= rows; r++) {
     for (int c = 1; c <= cols; c++)
if (c <= cols/2 - (r) || c >= cols/2 + (r)) cout << " ";
else cout << "*";
     cout << endl;
   }

   return 0;
}

the one to print a balanced triangle

No comments:

Post a Comment