c语言输入两个1*n的向量 a和b,并计算a'*b所得的n*n矩阵
时间: 2023-12-31 20:05:17 浏览: 75
```
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
printf("Enter the size of vectors: ");
scanf("%d", &n);
int *a = (int *)malloc(n * sizeof(int));
int *b = (int *)malloc(n * sizeof(int));
printf("Enter the elements of vector a: ");
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
printf("Enter the elements of vector b: ");
for (int i = 0; i < n; i++)
{
scanf("%d", &b[i]);
}
int **matrix = (int **)malloc(n * sizeof(int *));
for (int i = 0; i < n; i++)
{
matrix[i] = (int *)malloc(n * sizeof(int));
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
matrix[i][j] = a[i] * b[j];
}
}
printf("The matrix a'*b is:\n");
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
printf("%d ", matrix[i][j]);
}
printf("\n");
}
for (int i = 0; i < n; i++)
{
free(matrix[i]);
}
free(matrix);
free(a);
free(b);
return 0;
}
```
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![cpp](https://img-home.csdnimg.cn/images/20250102104920.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)