Advertisement
Guest User

main.cpp

a guest
Apr 7th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.   cout << "Excercise Solution - Duong Quang Tuan - 1920069\n";
  10.  
  11.   int N = -1;
  12.  
  13.   while(N <= 0){
  14.     cout << "Please input a positive number: ";
  15.     cin >> N;
  16.      
  17.     if(!cin.good()){
  18.         cin.clear();
  19.         cin.ignore(1024, '\n');
  20.     }
  21.   }
  22.  
  23.   int M = N%2 ? (2*N - 1) : 2*N;
  24.  
  25.   for(int i = 1; i <= N; i++){
  26.     for(int j = i; j > 0; j--){
  27.       cout << '*';
  28.     }
  29.  
  30.     for(int j = (N - i)*2 -1 ; j > 0; j--){
  31.       cout << ' ';
  32.     }
  33.  
  34.     for(int j = (i == N ? i-1 : i); j > 0; j--){
  35.       cout << '*';
  36.     }
  37.  
  38.     cout << '\n';
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement