wf = fopen(\
fprintf(wf, \fprintf(wf, \fclose(wf) ; }
27./* 请编一个函数add(),函数的功能计算5×5的矩阵中下三角元素之和。
下三角元素就是主对角线以下(含主对角线)的元素。
例如:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
下三角元素之和为220。
注意: 部分源程序存在文件PROG1.C文件中。
请勿改动主函数main和其它函数中的任何内容,仅在函数add的花括号中填入你编写的若干语句。*/
#include
int add(int a[5][5]);
int main( ) {
int a[5][5] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21, 22,23,24} ; int i , j ,sum = 0 ; for ( i = 0 ; i < 5 ; i++ ) { for ( j = 0 ; j < 5 ; j++) printf( \ printf( \ }
sum=add(a); printf( \ xqs(); return 0 ; }
int add(int a[5][5]) {
int s=0,i,j;
/**********Begin**********/ int sum=0; for(i=0;i<5;i++) for(j=0;j<=i;j++) sum+=a[i][j]; return sum;
/********** End **********/ }
void xqs() {
int i,j, a[5][5],s; FILE *rf, *wf ;
if((rf = fopen(\ {
printf(\exit(0); }
if((wf=fopen(\ {
printf(\exit(0); }
for(i = 0 ; i <5; i++) for(j=0;j<5;j++)
fscanf(rf, \
s=add(a);
fprintf(wf, \
fclose(rf) ; fclose(wf) ; }
//判断文件是否成功打开
28./* 请编一个函数fun,函数的功能是计算三角形面积
注意: 部分源程序存在文件PROG1.C文件中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。*/
#include
double fun(double x,double y,double z); void xqs();
int main( ) { double a , b , c , s ; a = 3.0 ; b = 4.0 ; c = 5.0 ; s=fun(a,b,c); printf( \ xqs(); return 0 ; }
double fun(double x,double y,double z) {
/********** Begin **********/ double p,a , b , c , s ; a = 3.0 ; b = 4.0 ; c = 5.0 ;
p=0.5*(a+b+c);
s=sqrt(p*(p-a)*(p-b)*(p-c));
/********** End **********/ }
void xqs() {
double a,b,c;
FILE *rf, *wf ;
rf = fopen(\wf = fopen(\
fscanf(rf, \
fprintf(wf, \
fclose(rf) ; fclose(wf) ; }
30./* 请编一个函数stringlen(),函数的功能计算字符串的长度。不能使用strlen函数。
注意: 部分源程序存在文件PROG1.C文件中。
请勿改动主函数main和其它函数中的任何内容,仅在函数stringlen的花括号中填入你编写的若干语句。
#include
int stringlen(char s[]); int main( ) { char s1[100] ; int i ; printf( \ gets( s1 ) ; i=stringlen(s1); printf( \ xqs(); return 0 ; }
int stringlen(char s1[100]) {
/**********Begin**********/ int i;
for(i=0;i<100;i++)
{
if(s1[i]=='\\0') break; }
return i;
/********** End **********/ }
void xqs() {
int i,j,len;
char s1[100],s2[100];; FILE *rf, *wf ;
if((rf = fopen(\ {
printf(\exit(0); }
if((wf=fopen(\//判断文件是否成功打开 {
printf(\exit(0); }
fgets(s1, 100, rf) ; len=stringlen(s1);
fprintf(wf,\fputs(s1,wf); fprintf(wf,\
fprintf(wf, \
fclose(rf) ; fclose(wf) ; }
31./* 请编一个函数fun,函数的功能是计算两个自然数的最小公倍数。

