gpt4 book ai didi

C语言如何修复我的调用函数

转载 作者:太空宇宙 更新时间:2023-11-04 01:01:22 24 4
gpt4 key购买 nike

我添加了一个 void 函数和一个 int 函数。 void 函数工作得很好,但 int 函数不起作用,我已经确定包含一个 return,因为它需要一个。我认为这主要与我的电话有关。我在这里错过了什么或做错了什么?提前感谢您的帮助!

#include <stdio.h>

void multi_vec(int v1[], int v2[], int v3[], int n);

int comp_vec(int v1[], int v2[], int n);

int main(){

int n = 0;
int i = 0;

printf("Enter the length of the vectors: ");
scanf("%d",&n);

int v1[n];
int v2[n];
int v3[n];

printf("Enter the first vector: ");
for(i = 0; i < n; i++){
scanf("%d",&v1[i]);
}

printf("Enter the second vector");
for(i = 0; i < n; i++){
scanf("%d",&v2[i]);
}

multi_vec(v1, v2, v3, n);

printf("The multiplication of the vectors is: ");
for(i = 0; i < n; i++){
printf("%d",v3[i]);
printf(" ");
}

int compare;
compare = comp_vec(v1,v2,v3,n); //this is where I think I went wrong

}

void multi_vec(int v1[], int v2[], int v3[], int n){

int i;

for(i = 0; i < n; i++){

v3[i] = v1[i] * v2[i];

}
}
int comp_vec(int v1[], int v2[], int v3[], int n){

int i;

for(i=0; i < n; i++){
if(v1[i] != v2[i]){
printf("not the same");
return 0;
}

else{
printf("are the same");
return 0;
}
}
}

最佳答案

函数声明

int comp_vec(int v1[], int v2[], int n); //3 param

与函数定义不匹配

int comp_vec(int v1[], int v2[], int v3[], int n){ // 4 param

关于C语言如何修复我的调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37599024/

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