Last active
June 20, 2017 21:06
-
-
Save Demonstrandum/f21e3d44b3ccd091997a23504367e2a9 to your computer and use it in GitHub Desktop.
Prints a cross of stars (`*`)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
#include <string> | |
using namespace std; | |
void starCross(int n) { | |
float half = (float)n * 0.5; | |
for (int i = 1; i <= floor(half); i++) { | |
for (int j = 1; j < i; j++) { | |
cout << " "; | |
} | |
cout << "*"; | |
for (int j = 1; j < (n + 1) - 2*i; j++) { | |
cout << " "; | |
} | |
cout << "*" << endl; | |
} | |
if (n % 2 == 1) { | |
for (int i = 0; i < floor(half); i++) { | |
cout << " "; | |
} | |
cout << "*" << endl; | |
} | |
for (int i = floor(half); i >= 1; i--) { | |
for (int j = 1; j < i; j++) { | |
cout << " "; | |
} | |
cout << "*"; | |
for (int j = 1; j < (n + 1) - 2*i; j++) { | |
cout << " "; | |
} | |
cout << "*\n"; | |
} | |
} | |
int main(int argc, char** argv) { | |
if (argc < 2) { | |
cout << "Please supply a size for the cross." << endl; | |
return 1; | |
} | |
int size = stoi(argv[1]); | |
starCross(size); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: