Skip to content

Instantly share code, notes, and snippets.

@mgarod
Created September 16, 2016 18:11
Show Gist options
  • Save mgarod/9979dd974ee1a13e1767e26ec4f1642b to your computer and use it in GitHub Desktop.
Save mgarod/9979dd974ee1a13e1767e26ec4f1642b to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void printTriangle(int n) {
for (int i = 0; i < n; ++i) {
for (int j = ((2*n-1) - (2*i+1))/2; j > 0; --j){
cout << " ";
}
for (int k = (2*i+1); k > 0; --k){
cout << "*";
}
cout << endl;
}
}
int main() {
int n;
cin >> n;
printTriangle(n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment