prowessapps.in Pattern Programs

Pattern 1
 
*
**
***
****
*****

#include<iostream>
using namespace std;
int main() {
for(int i = 1; i<=5; i++) {
 for(int j = 1; j<=i; j++) {
  cout<<"*";
 }
 cout<< endl;
}
return 0;
}

Pattern 2

     *
    * *
   * * *
  * * * *
 * * * * *

#include<iostream>
using namespace std;
int main() {
for(int i = 1; i<=5; i++) {
 for(int j = 5; j>=i; j--) {
  cout<<" ";
 }
 for(int k = 1; k<=i; k++) {
  cout<<"* ";
 }
 cout<< endl;
}
return 0;
}

Pattern 3
 
A
A B
A B C
A B C D
A B C D E

#include<iostream>
using namespace std;
int main() {
for(char i = 'A'; i<='E'; i++) {
 for(char j = 'A'; j<=i; j++) {
  cout<< j;
 }
 cout<< endl;
}
return 0;
}

Pattern 4

   1
  121
 12321
1234321

#include<iostream>
using namespace std;
int main() {
for(int i = 1; i<=5; i++) {
 for(int j = 5; j>=i; j--) {
  cout<<" ";
 }
 for(int k = 1; k<=i; k++) {
  cout<< k;
 }
 for(int m = i-1; m>=1;m--) {
  cout<< m;
 }
 cout<< endl;
}
return 0;
}

Pattern 5
 
1
21
123
4321
12345

#include<iostream>
using namespace std;
int main() {
 for(int i = 1; i<=5; i++) {
  if(i%2==0){
   for(int j = 1; j<=i; j++) {
    cout<< j;
   }
  }
  else {
   for(int j = i; j>=1; j--) {
    cout<< j;
   }
  }
 cout<< endl;
 }
return 0;
}

Pattern 6

1234321
 12321
  121
   1

#include<iostream>
using namespace std;
int main() {
 for(int i =1; i<=4; i++) {
  for(int j =1; j< i;j++) {
   cout<<" ";
  }
  for(int j = 1; j<=5-i; j++) {
   cout<< j;
  }
  for(int k = 4-i;k>=1; k--) {
   cout<< k;
  }
  cout<< endl;
  }
 return 0;
}

Pattern 7
 
0
1 0
0 1 0
1 0 1 0
0 1 0 1 0

#include<iostream>
using namespace std;
int main() {
 for(int i = 0; i<=4; i++) {
  for(int j = 0; j<=i; j++) {
   cout<<(i+j)%2;
  }
  cout<< endl;
 }
 return 0;
}

Pattern 8

   *
  ***
 *****
  ***
   *

#include<iostream>
using namespace std;
int main() {
 int n,i,j,k;
 cout<<"Enter the value for N : ";
 cin>>n;
 for(i = 1; i<=n; i++) {
  for(j = 0; j< n-i; j++) {
   cout<<" ";
  }
  for(k=0; k< (2*i)-1; k++) {
   cout<<"*";
  }
  cout<< endl;
 }
 for(i = 1; i< n;i++) {
  for(j = 0; j< i; j++) {
   cout<<" ";
  }
  for(k = 0; k< 2*(n-i)-1; k++) {
   cout<<"*";
  }
  cout<< endl;
 }
return 0;
}


Pattern 9
 
2
4 6
8 10 12

#include<iostream>
using namespace std;
int main() {
 int k = 1;
 for(int i = 1; i< 4; i++) {
  for(int j = 1; j<=i; j++) {
   cout<< 2*k<<" ";
   k++;
  }
  cout<< endl;
 }
return 0;
}

Pattern 10

1
3 3
5 5 5
7 7 7 7

#include<iostream>
using namespace std;
int main() {
 int i,j;
 for(i = 0; i< 4; i++) {
  for(j = 0; j<=i; j++) {
   cout<< (2*i)+1<<" ";
  }
  cout<< endl;
 }

return 0;
}

Floyd's Triangle
 
1
2 3
4 5 6
7 8 9 10

#include<iostream>
using namespace std;
int main() {
 int k = 1;
 for(int i = 1; i<=4; i++) {
  for(int j = 1; j<=i; j++) {
   cout<< k<<" ";
   k++;
  }
  cout<< endl;
 }
 return 0;
}

Pascal's Triangle

   1
  1 1
 1 2 1
1 3 3 1

#include<iostream>
using namespace std;
int fact(int x) {
 int res = 1;
 for(int i = 1; i< x; i++) {
  res = res*i;
 }
 return res;
}
int main() {
 int n;
 cout<<"Enter the value for N: ";
 cin>>n;
 for(int i=0; i<=n; i++) {
  for(int c = 0; c <= (n-i-2); c++) {
   cout<<" ";
  }
 for(int c =0; c< i; c++) {
  cout<< fact(i)/(fact(c)*fact(i-c));
 }
  cout<< endl;
 }
return 0;
}



Get it on Google Play


CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-9026070669 , +91-9451396824

© 2016, prowessapps.in, All rights reserved