Advertisement
fahimkamal63

Pattern printing

Oct 18th, 2019
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. //  Pattern printing
  2. //  Date : 18.10.19
  3. #include<iostream>
  4. using namespace std;
  5.  
  6. void pattern1(int n){
  7.     for(int i = 0; i < n; i++){
  8.         for(int j = i; j < n; j++){
  9.             cout << " ";
  10.         }
  11.         for(int j = 0; j <= i; j++){
  12.             cout << "* ";
  13.         }
  14.         cout << endl;
  15.     }
  16. }
  17.  
  18. void pattern2(int n, int a){
  19.     for(int i = 0; i < n-a; i++){
  20.         cout << ' ';
  21.     }
  22.     for(int i = 0; i < a; i++){
  23.         cout << "* ";
  24.     }
  25.     cout << endl;
  26.     if(a == n) return;
  27.     pattern2(n, a + 1);
  28.     for(int i = 0; i < n-a; i++){
  29.         cout << ' ';
  30.     }
  31.     for(int i = 0; i < a; i++){
  32.         cout << "* ";
  33.     }
  34.     cout << endl;
  35. }
  36.  
  37. void pattern3(int n, int a){
  38.     for(int i = 0; i < a; i++){
  39.         cout << "* ";
  40.     }
  41.     cout << endl;
  42.     if(a == n) return;
  43.     pattern3(n, a + 1);
  44.     for(int i = 0; i < a; i++){
  45.         cout << "* ";
  46.     }
  47.     cout << endl;
  48. }
  49. #include<cstdio>
  50. void pattern4(int n){
  51.     int k = 1;
  52.     for(int i = 0; i < n; i++){
  53.         for(int j = i; j < n; j++){
  54.             cout << "  ";
  55.         }
  56.         for(int j = 0; j <= i; j++){
  57.             printf("%02d  ", k++);
  58.         }
  59.         cout << endl;
  60.     }
  61. }
  62.  
  63. void pattern5(int n){
  64.     char ch = 'A';
  65.     for(int i = 0; i < n; i++){
  66.         for(int j = 0; j <= i; j++, ch++){
  67.             cout << ch << ' ';
  68.         }
  69.         cout << endl;
  70.     }
  71. }
  72.  
  73. void pattern6(int n){
  74.     char ch = 'A';
  75.     for(int i = 0; i < n; i++, ch++){
  76.         for(int j = 0; j < n-i; j++){
  77.             cout << ' ';
  78.         }
  79.         for(int j = 0; j <= i; j++){
  80.             cout << ch << ' ';
  81.         }
  82.         cout << endl;
  83.     }
  84. }
  85.  
  86. int main(){
  87.     cout << "Enter the value of n: ";
  88.     int n; cin >> n;
  89.     pattern1(n);
  90.     pattern2(n, 1);
  91.     pattern3(n, 1);
  92.     pattern4(n);
  93.     pattern5(n);
  94.     pattern6(n);
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement