c语言:求平均年龄 谁能帮我写一下一下源代码的注释 //?的地方

#include<stdio.h>
#include<stdlib.h>
int main()
{
int age[4];
int top=-1;
int i;
float avg;
int temp;// 定义数据交换时的暂存变量
char t1;
FILE *in;
in=fopen("family.txt","r");//建立文件流,返回该文件的指针
while (fscanf(in,"%d",&temp)!=EOF)/*从文件流中按格式读取数据,只要读到数据,
while 继续循环,读到错误数据(例如整数写成字母),或没成功读到数据,或
读到EOF, 则退出 while 循环*/
{
t1=fgetc(in);// 从文件中读取一个字符
age[++top]=temp;//临时存入age数组
if (t1=='\n')
{
avg=0;
for (i=0;i<=top;i++)//?
{
avg+=age[i];//?
}
avg=avg/(top+1);
printf("%5.2f:",avg);//输出年龄平均值
for (i=0;i<top;i++)//?
{
printf("%d ",age[i]);
}//?
printf("%d\n",age[i]);
top=-1;//?
}

}
system("pause");
return 0;
}

第1个回答  2012-06-23
#include<stdio.h>
#include<stdlib.h>
int main()
{
int age[4];
int top=-1;
int i;
float avg;
int temp;// 定义数据交换时的暂存变量
char t1;
FILE *in;
in=fopen("family.txt","r");//建立文件流,返回该文件的指针
while (fscanf(in,"%d",&temp)!=EOF)/*从文件流中按格式读取数据,只要读到数据,
while 继续循环,读到错误数据(例如整数写成字母),或没成功读到数据,或
读到EOF, 则退出 while 循环*/
{
t1=fgetc(in);// 从文件中读取一个字符
age[++top]=temp;//临时存入age数组
if (t1=='\n')
{
avg=0;
for (i=0;i<=top;i++)//读取数组中的数
{
avg+=age[i];//求总和
}
avg=avg/(top+1);
printf("%5.2f:",avg);//输出年龄平均值
for (i=0;i<top;i++)//输出数组值
{
printf("%d ",age[i]);
}
printf("%d\n",age[i]);
top=-1;//数组清零
}

}
system("pause");
return 0;本回答被提问者采纳
相似回答