題目如下
2. Write a program to obtain the sum of two 2D arrays (i.e., matrices). You will ask the user to input the size of the matrices as well as the matrices. Use pointers in the program.
翻譯: 寫一個計算兩個二維陣列和程式,讓使用者輸入陣列大小以及數字,并在程式中使用指標
下面是我寫的 ,就不知道怎么寫了
#include<stdio.h>
void sum(int*(a)[c],int*(b)[d],int c,int d,int e,int f)
{
int c,d,e,f;
int sum1=0;
int sum2=0;
for(c=0;c<j;c++){
for(d=0;d<k;d++){
sum1+=*(*(a+c)+k);
}
}
for(d=0;d<l;d++){
for(f=0;f<m;f++){
sum2+=*(*(b+c)+d);
}
}
printf("sum in total is%d",sum1+sum2);
}
int main()
{
int j,k,l,m;
printf("please input the size of array a[][] in 2 dimentions:\n");
scanf("%d%d",&j,&k);
printf("please input the size of array b [][]in 2 dimentions:\n");
scanf("%d%d",&l,&m);
int i,h;
int a[j][k];
int b[l][m];
for(i=0;i<j;i++){
for(h=0;h<k;h++){
printf("please input the value in a[%d][%d]",i,h);
scanf("%d",a[i][h]);
}
}
int o,p;
for(o=0;o<l;o++){
for(p=0;p<m;p++){
printf("please input the value in b[%d][%d]",o,p);
}
}
sum(*a,*b,j,k,l,m);
return 0;
}
uj5u.com熱心網友回復:
https://www.cnblogs.com/gmengshuai/p/13976038.html轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/225188.html
標籤:新手樂園
