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

2*2

3*3*3

2*2

1