#include <iostream> using namespace std; int main() { int n,i; cin>>n; int arr1[n+1][n+1],arr2[n+1][n+2],arr3[n+1][n+3]; for(int i=1;i<=n;i++) { arr1[i][i]=n; } int pos; for(int i=1;i<=n;i++) { pos=1; int temp=n; while(pos!=1) { arr1[i][pos-1]=temp-2; temp=temp-2; pos--; } temp=n; pos=i; while(pos!=n) { arr1[i][pos+1]=temp-2; temp=temp-2; pos++; } } int temp2=n+(n-1)*2; for(int i=1;i<=n;i++) { int loop=temp2; int step=0; int step2=0; for(int j=1;j<=n;j++) { if (loop>n) { arr2[i][j]=temp2-step; step+=2; loop-=2; }else if (loop<n) { arr2[i][j]=temp2-step+step2; step2+=2; }else { arr2[i][j]=n; loop-=2; step2+=2; } } temp2-=2; } int temp3=n+(n/2)-1; for(int j=1;j<=n/2;j++) { arr3[i][j]=temp3; temp3--; } cout<<"\ntype 1"<<endl; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { cout<<arr1[i][j]<<""; } cout<<endl; } cout<<"\ntype 2"<<endl; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { cout<<arr2[i][j]<<""; } cout<<endl; } cout<<"\ntype 3"<<endl; for(int k=1;k<=3;k++) { for(int i=1;i<=2;i++) { for(int j=1;j<=n/2;j++) { cout<<arr3[1][j]<<""; } } cout<<endl; } for(int k=1;k<=3;k++) { for(int i=1;i<=2;i++) { for(int j=n/2;j>=1;j--) { cout<<arr3[1][j]<<""; } } cout<<endl; } return 0; }
#include <stdio.h> int main() { int n,i; printf("enter number"); int arr1[n+1][n+1],arr2[n+1][n+1],arr3[n+1][n+1]; for(int i=1;i<=n;i++) { arr1[i][i]=n; } int pos; for(int i=1;i<=n;i++) { pos=1; int temp=n; while(pos!=1) { arr1[i][pos-1]=temp-2; temp=temp-2; pos--; } temp=n; pos=i; while(pos!=n) { arr1[i][pos+1]=temp-2; temp=temp-2; pos++; } } int temp2=n+(n-1)*2; for(int i=1;i<=n;i++) { int loop=temp2; int step=0; int step2=0; for(int j=1;j<=n;j++) { if (loop>n) { arr2[i][j]=temp2-step; step+=2; loop-=2; }else if (loop<n) { arr2[i][j]=temp2-step+step2; step2+=2; }else { arr2[i][j]=n; loop-=2; step2+=2; } } temp2-=2; } int temp3=n+(n/2)-1; for(int j=1;j<=n/2;j++) { arr3[i][j]=temp3; temp3--; } printf("\ntype 1"); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { printf("%d",arr1[i][j]); } printf("\n"); } printf("\ntype 2"); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { printf("%d",arr2[i][j]); } printf("\n"); } printf("\ntype 3"); for(int k=1;k<=3;k++) { for(int i=1;i<=2;i++) { for(int j=1;j<=n/2;j++) { printf("%d",arr3[i][j]); } } printf("/n"); } for(int k=1;k<=3;k++) { for(int i=1;i<=2;i++) { for(int j=n/2;j>=1;j--) { printf("%d",arr3[i][j]); } } printf("/n"); } return 0; }
iostream
stdio.h
cin >> n
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)