fork download
  1. #include <iostream>
  2. using namespace std;
  3. void patterns(int n){
  4. int spaces = n/2;
  5. int stars = 1;
  6. for(int i =1;i<=n;i++){
  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<=stars;j++){
  17. cout<<"*"<<" ";
  18. }
  19. if(i<=n/2){
  20. stars++;
  21. }
  22. else{
  23. stars--;
  24. }
  25. cout<<"\n";
  26. }
  27. }
  28. int main() {
  29. // your code goes here
  30. int n;
  31. cin>>n;
  32. patterns(n);
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5536KB
stdin
5
stdout
		*	
		*	*	
*	*	*	*	*	
		*	*	
		*