Skip to content

Instantly share code, notes, and snippets.

@0001vrn
Created April 23, 2017 07:12
Show Gist options
  • Select an option

  • Save 0001vrn/a072a93a1c3d90b74cd961138e524359 to your computer and use it in GitHub Desktop.

Select an option

Save 0001vrn/a072a93a1c3d90b74cd961138e524359 to your computer and use it in GitHub Desktop.
#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