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