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

标签 c arrays function vector

我添加了一个 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/

相关文章:

c程序计算区间的倍数

c - 如何使用 Libwebsockets 启用调试日志记录?

c++ - 轮廓 opencv : How to eliminate small contours in a binary image

php - 在 PHP 中,如何将对象元素添加到数组中?

javascript - Facebook javascript 在登录时调用的函数运行两次,但应该只运行一次

c - GtkContainer/GtkWidget 最大宽度

JavaScript - 数组 "undefined"错误

c++ - 如何从成员函数返回对新对象实例的引用(在某些操作之后)?

java - 参数的变量作为参数

c - 两个字符串应该是不同的长度,但被算作相同的长度