Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- void printStar(int n) {
- for (int i=0; i<n; i++) {
- std::cout << "*";
- }
- std::cout << "\n";
- }
- void printSpace(int n) {
- for (int i=0; i<n; i++) {
- std::cout << " ";
- }
- }
- void print(int n){
- int space = 0;
- for (int i=n; i> 0; i=i-2){
- printSpace(space++);
- printStar(i);
- }
- for (int i=1; i<=n; i=i+2){
- printSpace(--space);
- printStar(i);
- }
- }
- int main(int argc, const char * argv[]) {
- print(7);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment