www.whkt.net > C语言编写螺旋矩阵用C语言怎么编写螺旋矩阵

C语言编写螺旋矩阵用C语言怎么编写螺旋矩阵

#include #define N 20 void matrx1(int a[][N],int m,int n) { int d,x=0,y=0; int right,left,up,down; for(d=1;d#include #include #include #define N 5 void main() { int arry[N][N]={0}; inti,j,a,b; int n=1; int L; L=(N+1)/2; for (i=0;i

#include <stdio.h>#include<stdlib.h> void main(){ int i,j,n,number=1,a[30][30]; printf("please input a number n:"); scanf("%d",&n); for(i=0;i<=n/2;i++) //控制总共有几个顺时针螺旋 { for(j=i;j<n-i;j++) //向右(改变纵坐标,保持横坐标不变) a[i][j

#include #define MAXN 10 char m[MAXN+2][MAXN+2]; char d; int x,y,k,n; void main() { while (1) { printf("Input n(1..%d):",MAXN); fflush(stdout); rewind(stdin); if (1==scanf("%d",&n)) { if (1 } } y=0 ;for (x=0;x y=n+1;for (x=0;x x=0 ;for (y=0;y x=n+1;

#include &lt;stdio.h&gt;#include &lt;memory.h&gt;#include &lt;cstring&gt;#define N 5void main(){ int arry[N][N]={0}; int i,j,a,b; int n=1; int L; L=(N+1)/2; for (i=0;i&lt;L;i++) { b=i; for (a=i;a&lt;N-i;a++) { arry[a][b]=n++; } a--; for (b=i+1;b&lt;N-i;b++) { arry[a][b]

#include void main() { int i = 0; int j = 0; int k = 0; int data[20][20]={0}; int count = 0; int N = 0; printf("Input an integer N:\n"); scanf("%d",&N); for(k = 0;k { for(i = k;i data[k][i] = ++count; for(i = k+1;i data[i][N-k-1] = ++count; for(i = N-k-2;i > k; i--)

这里以顺时针旋转90°为例:#include<stdio.h>#include<stdlib.h>#include<time.h>#define N 4void main(){ int i,j; int a[N*N],b[N][N];//这里设置旋转为4*4的矩形,自己在这里改成其它的矩形 int *p=a;//用指针来指向这个一维数组.这样在旋转赋值

#include#define N 20 void matrx1(int a[][N],int m,int n) { int d,x=0,y=0; int right,left,up,down; for(d=1;d { a[x][y]=d; right=y left=y>0&&a[x][y-1]==0; down=x up=x>0&&a[x-1][y]==0; /* if(right||down) y++; else x++; if(down||left) x++; else if(left||up) y--; else if(

#include #define N 6 int a[N][N]; void go(int i,int j,int dir,int start,int final); int main(void) { int n; int i,j; for(i=0;i<N;j++) a[i][j]=0;

#include<stdio.h> #define N 20void matrx1(int a[][N],int m,int n){ int d,x=0,y=0; int right,left,up,down; for(d=1;d<=m*n;d++) {a[x][y]=d; right=y<n-1&&a[x][y+1]==0; left=y>0&&a[x][y-1]==0; down=x<m-1&&a[x+1][y]==0; up=x>0&&a[x-1][y]==0; /* if(right||

螺旋矩阵:#include main() { int a,b,k,n,i,j,a1,b1,m; int lines[50][50]; scanf("%d",&n); i=j=0;a=b=n;a1=b1=0;k=1; if(n==1) printf(" 1\n"); else { for(m=1;m=b1;j--) { lines[i][j]=k; k++; } i--; j++; b1++; } else { for(;i>=a1+1;i--) { lines[i][j]=k; k++;

友情链接:bycj.net | nnpc.net | famurui.com | hbqpy.net | knrt.net | 网站地图

All rights reserved Powered by www.whkt.net

copyright ©right 2010-2021。
www.whkt.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com