fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int rows=6;
  7. int cols=4;
  8. //printing half pyramid using *
  9. for( int i = 0; i < rows; i++ ) {
  10. for( int j = 0; j <= i; j++ ){
  11. cout << "* ";
  12. }
  13. cout<<endl;
  14. }
  15.  
  16. //using numbers
  17. for( int i = 0; i < rows; i++ ) {
  18. for( int j = 0; j <= i; j++ ){
  19. cout << i + 1 << " ";
  20. }
  21. cout<<endl;
  22. }
  23.  
  24. //usimg alphabets
  25. for( int i = 0; i < rows; i++ ) {
  26. for( int j = 0; j <= i; j++ ){
  27. cout << (char)('A' + j) << " ";
  28. }
  29. cout<<endl;
  30. }
  31.  
  32. // Main logic to print Rectangle.
  33. for( int i = 0; i < rows; i++ ) {
  34. for( int j = 0; j < cols; j++ ){
  35. cout << "* ";
  36. }
  37. cout<<endl;
  38. }
  39.  
  40. // Main logic to print hollow rectangle.
  41. for (int i = 0; i < rows; i++) {
  42. for (int j = 0; j < cols; j++) {
  43.  
  44. // If the index is at the border, then print *.
  45. if (i == 0 || i == rows - 1 || j == 0 || j == cols - 1)
  46. cout << "* ";
  47. else
  48. cout << " ";
  49. }
  50. cout << endl;
  51. }
  52.  
  53. // Main logic to print Floyd's Triangle.
  54. int counter = 1;
  55. for( int i = 0; i < rows; i++ ) {
  56. for( int j = 0; j <= i; j++ ){
  57. cout << (counter++) << " ";
  58. }
  59. cout << endl;
  60. }
  61.  
  62. // Main logic to print the Butterfly pattern.
  63. // Printing upper part.
  64. for( int i = 0; i <= rows; i++ ){
  65. // Print left side stars.
  66. for( int j = 0; j <= i; j++ ){
  67. cout << "* ";
  68. }
  69.  
  70. // Print spaces.
  71. int spaces = 2 * (rows - i);
  72. for( int j = 0; j < spaces; j++){
  73. cout << " ";
  74. }
  75.  
  76. // Print right side stars.
  77. for( int j = 0; j <= i; j++ ){
  78. cout << "* ";
  79. }
  80.  
  81. cout << endl;
  82. }
  83.  
  84. // Printing bottom part.
  85. for( int i = rows - 1; i >= 0; i-- ){
  86.  
  87. // Print left side spaces.
  88. for( int j = 0; j <= i; j++ ){
  89. cout << "* ";
  90. }
  91.  
  92. // Print spaces.
  93. int spaces = 2 * (rows - i);
  94. for( int j = 0; j < spaces; j++){
  95. cout << " ";
  96. }
  97.  
  98. // Print right side stars.
  99. for( int j = 0; j <= i; j++ ){
  100. cout << "* ";
  101. }
  102. cout << endl;
  103. }
  104.  
  105. // Main logic to print Pascal's triangle.
  106. for( int i = 0; i < rows; i++){
  107. int spaces = rows - i;
  108. // Print spaces.
  109. for( int j = 0; j < spaces; j++){
  110. cout<<" ";
  111. }
  112.  
  113. int coefficient;
  114. // Print values.
  115. for( int j = 0; j <= i; j++){
  116. // Update coefficient's value
  117. if( j == 0 )
  118. coefficient = 1;
  119. else
  120. coefficient = coefficient * (i - j + 1) / j;
  121. cout << coefficient << " ";
  122. }
  123.  
  124. cout << endl;
  125. }
  126. // Main logic to print full pyramid.
  127. for( int i = 0; i < rows; i++ ) {
  128. // Print spaces.
  129. int spaces = rows - i;
  130.  
  131. for( int j = 0; j < spaces; j++){
  132. cout <<" ";
  133. }
  134.  
  135. // Print stars.
  136. for( int j = 0; j < 2 * i - 1; j++){
  137. cout <<"* ";
  138. }
  139.  
  140. cout << endl;
  141.  
  142. }
  143. return 0;
  144. }
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
*  
*  *  
*  *  *  
*  *  *  *  
*  *  *  *  *  
*  *  *  *  *  *  
1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 
6 6 6 6 6 6 
A 
A B 
A B C 
A B C D 
A B C D E 
A B C D E F 
* * * * 
* * * * 
* * * * 
* * * * 
* * * * 
* * * * 
* * * * 
*     * 
*     * 
*     * 
*     * 
* * * * 
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 
16 17 18 19 20 21 
*                         * 
* *                     * * 
* * *                 * * * 
* * * *             * * * * 
* * * * *         * * * * * 
* * * * * *     * * * * * * 
* * * * * * * * * * * * * * 
* * * * * *     * * * * * * 
* * * * *         * * * * * 
* * * *             * * * * 
* * *                 * * * 
* *                     * * 
*                         * 
            1   
          1   1   
        1   2   1   
      1   3   3   1   
    1   4   6   4   1   
  1   5   10   10   5   1   
            
          * 
        * * * 
      * * * * * 
    * * * * * * * 
  * * * * * * * * *