题目:用函数求一个N阶方阵右下三角元素的和(包括副对角线上的元素)。
#include <stdlib.h>
#include <stdio.h>
#define N 3
void wwjt();
int sum(int a[][N])
{
/**********Program**********/
/********** End **********/
}
main()
{
int a[N][N],i,j;
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
a[i][j]=random(10)+10;
printf("%3d",a[i][j]);
}
printf("\n");
}
printf("===================\n");
printf("sum=%5d\n",sum(a));
wwjt();
}
void wwjt()
{
FILE *IN,*OUT;
int m,n;
int i[3][3];
int o;
IN=fopen("in.dat","r");
if(IN==NULL)
{
printf("Read FILE Error");
}
OUT=fopen("out.dat","w");
if(OUT==NULL)
{
printf("Write FILE Error");
}
for(m=0;m<3;m++)
for(n=0;n<3;n++)
fscanf(IN,"%d",&i[m][n]);
o=sum(i);
fprintf(OUT,"%d\n",o);
fclose(IN);
fclose(OUT);
}
登录后提交答案