编写fun函数求1000以内7的倍数之和

2024-12-19 03:21:01
推荐回答(1个)
回答1:

#define N 1000
#include"stdio.h"
main()
{
int sum;
sum=fun(7);
printf("%d以内所有%d的倍数之和为:%d\n",N,7,sum);
getch();
yzj();
}
int fun(int m)
{int i,sum=0;
for(i=1;i if(i%m==0)sum+=i;
return sum;
}

yzj()
{
FILE *IN,*OUT;
int n;
int i[10];
int o;

OUT=fopen("out.dat","w");
if(OUT==NULL)
{printf("Write File Error");
}
o = fun(6);
fprintf(OUT,"%d\n",o);
fclose(IN); //没见着要打开啥文件哈
fclose(OUT);
}