2. seeking a 3 × 3 matrix of diagonal elements of the sum, product, upper triangular, lower triangular element and the.
#include <stdio.h>
#define N 3
int main()
{
int i,j,sum,ji,s3,x3;
sum=0,ji=1,s3=0,x3=0;
int a[N][N]={{1,2,3},{4,5,6},{7,8,9}};
printf("3x3矩阵\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%3d",a[i][j]);
}
printf("\n");
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
if(i<=j)
{
s3+=a[i][j];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
if(j<=i)
{
x3+=a[i][j];
}
}
for(i=0;i<3;i++)
{
for(j=i;j<3;j++)
if(i==j)
{
sum=sum+a[i][j];
ji=ji*a[i][j];
}
}
printf("和=%d 积=%d 上三角和=%d 下三角和=%d",sum,ji,s3,x3);
}
6. Write a program seeking the rows and columns of a two-dimensional array of elements and. ( Program in question?)
#include <stdio.h>
#define N 3
int main()
{
int i,j,sum;
sum=0;
int a[N][N]={{1,2,3},{4,5,6},{7,8,9}};
printf("3x3矩阵\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%3d",a[i][j]);
}
printf("\n");
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
sum=sum+a[i][j];
}
printf("和=%d",sum);
}
1. Enter a positive integer n (1≤n≤10), generates n × n matrix according to the following equation, and then outputs the matrix.
A[i][j]=i×n+j+1
#include <stdio.h>
int main()
{
int i,j,n;
scanf("%d",&n);
int a[n][n]={0};
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=i*n+j+1;
printf("%4d",a[i][j]);
}
printf("\n");
}
}
3. Print the following Triangle (required to print out 10 lines).
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
…… …… ……
4. The programming to achieve B = A + A ', i.e. the transpose of the matrix A plus A and B are stored in the matrix.
#include<stdio.h>
int main()
{
int i,j,n,a[3][3],b[3][3];
n=0;
printf("请输入一个矩阵A:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
}
printf("请输入一个矩阵A的转置:\n");
for(j=0;j<3;j++)
{
for(i=0;i<3;i++)
scanf("%d",&a[j][i]);
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
b[i][j]=a[i][j]+a[j][i];
}
printf("矩阵B为:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%3d",b[i][j]);
}
printf("\n");
}
return 0;
}
5. Write a program seeking a two-dimensional array of elements and the four sides.
7. If the matrix A is non-boundary elements A [i] [j] is greater than four vertically and horizontally adjacent element, said A [i] [j] is the local maximum value matrix. Programming matrix output all local maxima. Matrix shall be determined by the experimenter.
8. programming, to achieve a sum of two squares (sum of the corresponding element), the difference (corresponding to difference of the element), the product of. The product of two matrices is given by C = A × B:
c ij = k = 0 p a i k × b k j = a i 0 × b 0 j + a s [1] × b 1 j + ... + a [i] [n] × b [i] [j] .