fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void print1(int n)
  5. {
  6. int i , j;
  7. for(i=0;i<n;i++)
  8. {
  9. for(j=0;j<n-i-1;j++)
  10. {
  11. cout << " ";
  12. }
  13.  
  14.  
  15. for(j=0;j<2*i+1;j++)
  16. {
  17. cout << " * ";
  18. }
  19.  
  20.  
  21. for(j=0;j<n-i-1;j++)
  22. {
  23. cout << " ";
  24. }
  25. cout << endl;
  26.  
  27. }
  28. }
  29.  
  30. void print2(int n)
  31. {
  32. int i , j;
  33. for(i=0;i<n;i++)
  34. {
  35. for(j=0;j<i;j++)
  36. {
  37. cout << " ";
  38. }
  39.  
  40.  
  41. for(j=0;j< (2*n)-(2*i+1);j++)
  42. {
  43. cout << " * ";
  44. }
  45.  
  46.  
  47. for(j=0;j<i;j++)
  48. {
  49. cout << " ";
  50. }
  51. cout << endl;
  52.  
  53. }
  54. }
  55. int main()
  56. {
  57. int n , i , j;
  58. cin >> n;
  59. print1(n);
  60. print2(n);
  61. }
  62.  
Success #stdin #stdout 0.01s 5288KB
stdin
5
stdout
         *         
       *  *  *       
     *  *  *  *  *     
   *  *  *  *  *  *  *   
 *  *  *  *  *  *  *  *  * 
 *  *  *  *  *  *  *  *  * 
   *  *  *  *  *  *  *   
     *  *  *  *  *     
       *  *  *       
         *