功能:编写函数求1~50(包括50)中奇数的平方和,结
功能:编写函数求1~50(包括50)中奇数的平方和,结果为20825.000000。
#include<stdio.h>
float sum(int n)
{
float s=0;
int i;
for(_____1_____)
_____2_____
_____3_____
}
void TestFunc()
{
FILE *IN,*OUT;
int i;
float 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");
}
fscanf(IN,"%d",&i);
o=sum(i);
fprintf(OUT,"%f\n",o);
fclose(IN);
fclose(OUT);
}
void main()
{
printf("sum=%f\n",sum(50));
TestFunc();
}答案
第1空:i=1;i<=n;i=i+2
第2空:s=s+i*i;
第3空:return s;