Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Pattern printing
- // Date : 18.10.19
- #include<iostream>
- using namespace std;
- void pattern1(int n){
- for(int i = 0; i < n; i++){
- for(int j = i; j < n; j++){
- cout << " ";
- }
- for(int j = 0; j <= i; j++){
- cout << "* ";
- }
- cout << endl;
- }
- }
- void pattern2(int n, int a){
- for(int i = 0; i < n-a; i++){
- cout << ' ';
- }
- for(int i = 0; i < a; i++){
- cout << "* ";
- }
- cout << endl;
- if(a == n) return;
- pattern2(n, a + 1);
- for(int i = 0; i < n-a; i++){
- cout << ' ';
- }
- for(int i = 0; i < a; i++){
- cout << "* ";
- }
- cout << endl;
- }
- void pattern3(int n, int a){
- for(int i = 0; i < a; i++){
- cout << "* ";
- }
- cout << endl;
- if(a == n) return;
- pattern3(n, a + 1);
- for(int i = 0; i < a; i++){
- cout << "* ";
- }
- cout << endl;
- }
- #include<cstdio>
- void pattern4(int n){
- int k = 1;
- for(int i = 0; i < n; i++){
- for(int j = i; j < n; j++){
- cout << " ";
- }
- for(int j = 0; j <= i; j++){
- printf("%02d ", k++);
- }
- cout << endl;
- }
- }
- void pattern5(int n){
- char ch = 'A';
- for(int i = 0; i < n; i++){
- for(int j = 0; j <= i; j++, ch++){
- cout << ch << ' ';
- }
- cout << endl;
- }
- }
- void pattern6(int n){
- char ch = 'A';
- for(int i = 0; i < n; i++, ch++){
- for(int j = 0; j < n-i; j++){
- cout << ' ';
- }
- for(int j = 0; j <= i; j++){
- cout << ch << ' ';
- }
- cout << endl;
- }
- }
- int main(){
- cout << "Enter the value of n: ";
- int n; cin >> n;
- pattern1(n);
- pattern2(n, 1);
- pattern3(n, 1);
- pattern4(n);
- pattern5(n);
- pattern6(n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement