编写一个将两个double类型的2-d数组作为参数的函数,并使此代码更好]] << [

问题描述 投票:0回答:1
编写一个函数,该函数接受两个double类型的2-d数组作为参数,其中每个数组都有其自己的行数和列数并进行比较。如果,则应返回1

两个数组的行数相同两个数组的列数相同第一个数组的每个元素与第二个数组的相应元素具有相同的值否则应返回0。

在主要函数中使用它,该函数生成两个二维数组,然后进行比较,如果数组与上面定义的相同,则输出。

int main(){ int n,m; printf("How many elements do you want in the first array's column:"); scanf("%d", &n); printf("How many elements do you want in the first array's row:"); scanf("%d", &m); int first[n][m]; srand(time(0)); for(int i=0; i<n; i++) { for(int j=0;j<m;j++) { first[i][j]=rand()%10+1; } } printf("First array:\n"); for(int i=0; i<n; i++) { for(int j=0;j<m; j++) { printf("%d ", first[i][j]); if(j==m-1){ printf("\n"); } } } int x,y; printf("How many elements do you want in the second array's column:"); scanf("%d", &x); printf("How many elements do you want in the second array's row:"); scanf("%d", &y); int second[x][y]; srand(time(0)); for(int i=0; i<x; i++) { for(int j=0;j<y;j++) { second[i][j]=rand()%10+1; } } printf("Second array:\n"); for(int i=0; i<x; i++) { for(int j=0;j<y; j++) { printf("%d ", second[i][j]); if(j==y-1){ printf("\n"); } } } if(n==x || m==y) return 1; else return 0; }

编写一个函数,该函数接受两个double类型的2-d数组作为参数,其中每个数组都有其自己的行数和列数并进行比较。如果两个数组都具有相同的值,则应返回1 ...
c arrays multidimensional-array dynamic-programming dynamic-memory-allocation
1个回答
0
投票
是,使用varable-length array(自C99起)
© www.soinside.com 2019 - 2024. All rights reserved.