请用C++ 编写程序,计算结果保存在TXT

来源:百度知道 编辑:UC知道 时间:2024/09/26 10:53:08
程序是:
#include <stdio.h>
#include<math.h>
void main ()
{
float A,B,x,y,I;
printf ("enter A and B \n");
scanf("%f%f",&A,&B);
printf("波长是%f,相位差是%f",A,B);

for (x=-35.0;x<35;x=x+0.14)
for(y=-35.0;y<35;y=y+0.14)
{ if (x*x+y*y<1225)
I=A*A*sin(atan2(x, y))*sin(atan2(x,y))*B;
else
I=0.0;
printf("%f ",I);
}
printf("\n");
}

最好,显示500*500的矩形的!
程序可改动
我用的是VC ++编译,并且我需要复制过去就直接能编译的程序,因为我vc还不是很了解!
麻烦你了
编译时:
ompiling...
数据1.c
d:\vc98\include\eh.h(32) : fatal error C1189: #error : "eh.h is only for C++!"
执行 cl.exe 时出错.

数据1.obj - 1 error(s), 0 warning(s)

还有能不能将运行结果导入excle结果最好500*500显示!
若excle不显示500*500,可以修改x=x+0.14和 y=y+0.14,显示100*100的!

其他地方可以改!

#include <stdio.h>
#include<math.h>
void main ()
{
FILE * fp = NULL;
fp = fopen("result.txt","w");
double A,B,x,y,I;
printf ("enter A and B \n");
scanf("%lf%lf",&A,&B);
printf("波长是%lf,相位差是%lf",A,B);
for (x=-35.0;x<35;x=x+0.14)
{
for(y=-35.0;y<35;y=y+0.14)
{
if (x*x+y*y<1225)
I=A*A*sin(atan2(x, y))*sin(atan2(x,y))*B;
else
I=0.0;
fprintf(fp,"%lf ",I);
}
fprintf(fp,"\n");
}
fclose(fp);
}

#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;

int main(){
ofstream fout("output.txt");
float A, B, x, y, l;
cout<<"enter A and B"<<endl;
cin>>A>>B;
cout<<"波长是"<<A<