Advertisement
Guest User

DAB

a guest
Feb 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5. int middle;
  6. int rows;
  7. cout << "Enter the number of '*'s on the middle row: ";
  8. cin >> middle;
  9. cout << "Enter the number of rows above and below the middle row: ";
  10. cin >> rows;
  11. if(middle - 2 * rows < 2){
  12. cout << "Invalid values. Exiting\n";
  13. return 0;
  14. }
  15. for(int i = 1; i <= rows; i++){
  16. for(int j = 1; j <= rows - i + 1; j++) cout << " ";
  17. for(int j = 1; j <= middle - 2 * (rows - i + 1); j++){
  18. cout << "*";
  19. }
  20. cout << "\n";
  21. }
  22. for(int i = 1; i <= middle; i++) cout << "*";
  23. cout << "\n";
  24. for(int i = 1; i <= rows; i++){
  25. for(int j = 1; j <= i; j++) cout << " ";
  26. for(int j = 1; j <= middle - 2 * i; j++){
  27. cout << "*";
  28. }
  29. cout << "\n";
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement