C语言编程? 文件方面的

来源:百度知道 编辑:UC知道 时间:2024/06/21 14:54:44
1 建立一个文件,名为File1.date,存储变量x和y的值。其中x由0到6.28。增量为0.1; y=sin(x)cos(x)

2 编写程序,读出上题建立的数据文件,将x和y的值显示在屏幕上。
6.28修改为6.2.。谢谢啊!

一楼的不对啊

有个问题,增量是0.1,怎么会取到6.28?

怎么了,程序有问题?计算不对还是读写文件有问题?

#include "stdio.h"
#include "conio.h"
#include "time.h"
#include "math.h"

void main()
{
FILE *f;
int n=1;
double x,y;

f=fopen("file1.dat","wb");

for(x=0;x<6.28;x+=0.1)
{
y=sin(x)*cos(x);
fprintf(f,"%lf,%lf\n",x,y);
}
fclose(f);

if((f=fopen("file1.dat","rb"))==NULL)
{
puts("open file error");
getch();
exit(-1);
}
while(!feof(f))
{
if(fscanf(f,"%lf,%lf\n",&x,&y))
printf("x=%lf,y=%lf\n",x,y);
else
break;
}
fclose(f);

getch();
}