首页 > 代码库 > 矩阵相加

矩阵相加

/* Note:Your choice is C IDE */
#include "stdio.h"
#include<stdlib.h>
#include<time.h>
#define N 4
void main()
{
    int a[N][N];
    int b[N][N];
    int z,x,c,d,p,i,j;
    for(c=0;c<N;c++)
     srand(time(0));
    a[0][c]=rand()%10;
     printf("\n\n");
     d=0,p=0;
	do {
	for (z=d;z<N;z++){
		a[d][z]=a[0][p];
		a[z][d]=a[0][p];
		p++;
	}
	d++;
	}
    while (d!=N);
   	for (x=0;x<N;x++){
		for (c=0;c<N;c++){
			printf ("%d ",a[x][c]);}
		    printf ("\n");}
   	 for(c=0;c<N;c++)
     srand(time(0));
     a[0][c]=rand()%10;
   
      printf("\n\n");
    d=0,p=0;
	do {
	for (z=d;z<N;z++){
		a[d][z]=a[0][p];
		a[z][d]=a[0][p];
		p++;
	}
	d++;
	}
    while (d!=N);
   	for (x=0;x<N;x++){
		for (c=0;c<N;c++){
			printf ("%d ",a[x][c]);}
		    printf ("\n\n");}
   	for(i=0;i<N;i++)
    {
    	for(j=0;j<N;j++)
    	{
    		b[i][j]=a[i][j]+a[i][j];
    		printf("%2d ",b[i][j]);
    	}
    	printf("\n\n");
    }
   	
   	
}