fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n ; cin>>n;
  7. int gap = n/2;
  8. for(int i =1;i<=n/2+1;i++){
  9.  
  10.  
  11. for(int j =1;j<=gap;j++){
  12. cout<<" ";
  13. }
  14. for(int j =1;j<=2*(i-1)+1;j++){
  15. cout<<"*";
  16. }
  17. gap--;
  18. cout<<endl;
  19. }
  20.  
  21. gap=1;
  22. for(int i =n/2;i>=1;i--){
  23.  
  24.  
  25. for(int j =1;j<=gap;j++){
  26. cout<<" ";
  27. }
  28. for(int j =2*(i-1)+1;j>=1;j--){
  29. cout<<"*";
  30. }
  31. gap++;
  32. cout<<endl;
  33. }
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5288KB
stdin
4
stdout
  *
 ***
*****
 ***
  *