下列程序定义了N×N的二维数组,并在主函数中自动赋值。 请编写函数fun(int a[][N],int n),该函数的功能是:将数组右上半三角元素中的值乘以m
/*下列程序定义了N×N的二维数组,并在主函数中自动赋值。
请编写函数fun(int a[][N],int n),该函数的功能是:将数组右上半三角元素中的值乘以m */
#include <stdio.h>
#define N 2
void fun(int buff[][N],int m, int n)
{
int k=0;
for(int j=0;j<n;j++)
{
for(int i=0;i<n;i++)
{
buff[j][i]*=m;
}
}
}
int main()
{
int buff[N][N];
int M=0;
printf("please enter number\n");
scanf("%d",&M);
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
printf("please enter buff[%d][%d] element\n",i+1,j+1);
scanf("%d",&buff[i][j]);
}
}
fun(buff,M,N);
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
printf("%d\n",buff[i][j]);
}
}
return 0;
}