fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5. // half pyramid using *
  6. int n;
  7. cin >>n;
  8. for( int i = 0; i < n; i++ ) {
  9. for( int j = 0; j <= i; j++ ){
  10. cout << "* ";
  11. }
  12. cout<<"\n";
  13. }
  14. // half pyramid using numbers
  15. for( int i = 0; i < n; i++ ) {
  16. for( int j = 0; j <= i; j++ ){
  17. cout <<i+1 <<"";
  18. }
  19. cout<<"\n";
  20. }
  21. // half pyramid using Alphabets
  22. for( int i = 0; i < n; i++ ) {
  23. for( int j = 0; j <= i; j++ ){
  24. cout << (char)('g' + j) << " ";
  25. }
  26. cout<<"\n";
  27. }
  28. // Rectangle pattern
  29. int p,s;
  30. cin>>p>>s;
  31. for( int i = 0; i <= p; i++ ) {
  32. for( int j = 0; j < s; j++ ){
  33. cout << "# ";
  34. }
  35. cout<<"\n";
  36. }
  37. // hollow rec
  38. // for( int i = 0; i <= p; i++ ) {
  39. // for( int j = 0; j < s; j++ ){
  40. // if(i == 0 || i ==p - 1 || j == 0 || j == s - 1);
  41. // cout << "* ";
  42. // else;
  43. // cout << " ";
  44. // }
  45. // cout<<"\n";
  46. // }
  47. // Floyd's triangle
  48. int k;
  49. cin >>k;
  50. int increaser = 1;
  51. for( int i = 0; i < k; i++ ) {
  52. for( int j = 0; j <= i; j++ ){
  53. cout << (increaser++) << " ";
  54. }
  55. cout<<"\n";
  56. }
  57. // butterfly
  58. int r;
  59. cin >>r;
  60. for( int i = 0; i <= r; i++ ){
  61. for( int j = 0; j <= i; j++ ){
  62. cout << "* ";
  63. }
  64. int gaps = 2 * (r - i);
  65. for( int j = 0; j < gaps; j++){
  66. cout << " ";
  67. }
  68. for( int j = 0; j <= i; j++ ){
  69. cout << "* ";
  70. }
  71.  
  72. cout <<"\n";
  73. }
  74. for( int i = r - 1; i >= 0; i-- ){
  75. for( int j = 0; j <= i; j++ ){
  76. cout << "* ";
  77. }
  78. int gaps = 2 * (r - i);
  79. for( int j = 0; j < gaps; j++){
  80. cout << " ";
  81. }
  82. for( int j = 0; j <= i; j++ ){
  83. cout << "* ";
  84. }
  85.  
  86. cout <<"\n";
  87. }
  88. // pascals triangle
  89. int h;
  90. cin >>h;
  91. for( int i = 0; i < h; i++){
  92. int gaps = h - i;
  93. for( int j = 0; j < gaps; j++){
  94. cout<<" ";
  95. }
  96.  
  97. int coefficient;
  98. for( int j = 0; j <= i; j++){
  99. if( j == 0 )
  100. coefficient = 1;
  101. else
  102. coefficient = coefficient * (i - j + 1) / j;
  103.  
  104. cout << coefficient << " ";
  105. }
  106.  
  107. cout <<"\n";
  108. }
  109. // pyramids
  110. int a;
  111. cin >> a;
  112. for( int i = 0; i < a; i++ ) {
  113. int gaps = a - i;
  114. for( int j = 0; j < gaps; j++){
  115. cout <<" ";
  116. }
  117. for( int j = 0; j < 2 * i - 1; j++){
  118. cout <<"* ";
  119. }
  120. cout <<"\n";
  121. }
  122. // sir i dont lnow how to call the function but the simple calculator and other two problems are calling the functons so they are not understanding so i stoped upto here iam requesting to teach how to call a function in next class.
  123. }
Success #stdin #stdout 0.01s 5292KB
stdin
6
4 6
7
6
7
6
stdout
*  
*  *  
*  *  *  
*  *  *  *  
*  *  *  *  *  
*  *  *  *  *  *  
1
22
333
4444
55555
666666
g 
g h 
g h i 
g h i j 
g h i j k 
g h i j k l 
# # # # # # 
# # # # # # 
# # # # # # 
# # # # # # 
# # # # # # 
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 
16 17 18 19 20 21 
22 23 24 25 26 27 28 
*                         * 
* *                     * * 
* * *                 * * * 
* * * *             * * * * 
* * * * *         * * * * * 
* * * * * *     * * * * * * 
* * * * * * * * * * * * * * 
* * * * * *     * * * * * * 
* * * * *         * * * * * 
* * * *             * * * * 
* * *                 * * * 
* *                     * * 
*                         * 
              1   
            1   1   
          1   2   1   
        1   3   3   1   
      1   4   6   4   1   
    1   5   10   10   5   1   
  1   6   15   20   15   6   1   
            
          * 
        * * * 
      * * * * * 
    * * * * * * * 
  * * * * * * * * *