gpt4 book ai didi

c - C 函数中的错误和警告

转载 作者:行者123 更新时间:2023-11-30 15:20:27 24 4
gpt4 key购买 nike

我的警告和错误,我需要修复错误:

exercici17b.c: In function ‘main’:
exercici17b.c:16:1: error: incompatible type for argument 1 of ‘imprimeixvector’
imprimeixvector(res[5], resu, mat[3][3], vect[3]);
^
exercici17b.c:4:5: note: expected ‘double *’ but argument is of type ‘double’
int imprimeixvector(double res[5], double resu, double mat[3][3], double vect[3]);
^
exercici17b.c:16:1: error: incompatible type for argument 3 of ‘imprimeixvector’
imprimeixvector(res[5], resu, mat[3][3], vect[3]);
^
exercici17b.c:4:5: note: expected ‘double (*)[3]’ but argument is of type ‘double’
int imprimeixvector(double res[5], double resu, double mat[3][3], double vect[3]);
^
exercici17b.c:16:1: error: incompatible type for argument 4 of ‘imprimeixvector’
imprimeixvector(res[5], resu, mat[3][3], vect[3]);
^
exercici17b.c:4:5: note: expected ‘double *’ but argument is of type ‘double’
int imprimeixvector(double res[5], double resu, double mat[3][3], double vect[3]);
^
exercici17b.c: In function ‘imprimeixvector’:
exercici17b.c:48:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^

我的代码是这样的:代码必须将矩阵乘以 vector 并将结果作为另一个 vector 给出,并且我在函数中遇到参数类型错误。

#include <stdio.h>
#include <math.h>

void imprimeixvector(double, double, double, double);

int main()
{
double res[5], resu=0;
double vect[3]={1.1, 2.2, 3.3};
double mat[3][3]={
{1., 1., 0.},
{0., 1., 1.},
{1., 0., 1.} //matriu 3x3
};

imprimeixvector(res[0], resu, mat[0][0], vect[0]);

printf("\n");
return 0;
}


void imprimeixvector(double res[5], double resu, double mat[3][3], double vect[3])
{
int i, j;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
res[i]=vect[j]*mat[i][j];
resu=resu+res[i];
}
printf("%d,", (int) resu);
resu=0;
}
}

最佳答案

替换

void imprimeixvector(double, double, double, double);

void imprimeixvector(double res[5], double resu, double mat[3][3], double vect[3]);

在声明中

然后在main中正确调用该函数

imprimeixvector(res, resu, mat, vect);

关于c - C 函数中的错误和警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30018730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com