Created
April 23, 2017 07:12
-
-
Save 0001vrn/a072a93a1c3d90b74cd961138e524359 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| void pattern1(int n){ | |
| int cnt=1; | |
| for(int i=0; i<2*n-1; i++){ | |
| for(int j=0; j<(abs(n-1-i)); j++)cout<<" "; | |
| for(int j=0; j<2*(n-abs(n-1-i))-1; j++)cout<<cnt++; | |
| cout<<endl; | |
| } | |
| } | |
| void pattern2(int n){ | |
| int i,j; | |
| for(i=0;i<2*n-1;i++){ | |
| for(j=0;j<2*n-1;j++) | |
| cout<< (1 + max( abs(n-i-1),abs(n-j-1) ) ); | |
| cout<<endl; | |
| } | |
| } | |
| int main() { | |
| // your code goes here | |
| pattern2(5); | |
| pattern1(4); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment