简单c语言度数转化为弧度 请高手指点指点 50
我想要把六个度数转化为弧度,h1a为“度”,h1b为“分”其他都一样,我分别把“度”“分”转化为弧度,然后相加.检查好几遍都觉得没错误,但输入数字得出结果确错误,如我输入...
我想要把六个度数转化为弧度,h1a为“度”,h1b为“分”其他都一样,我分别把“度”“分”转化为弧度,然后相加.检查好几遍都觉得没错误,但输入数字得出结果确错误,如我输入
h1=31°32′.5 Dec1 =22°28′.6S GHA1 =222°55′.1
h2=32°39′.0 Dec2 =19°12′.0N GHA2 =295°50′.3
h3=63°18′.4 Dec3 =45°15′.9N GHA3 =200°05′.8
结果为
0.532733 -1.85003940070e+297 3.890659
0.561996 0.331613 5.163353
1.104183 0.7853398 3.492346
第一个结果就错了,本来结果为0。55056 -0。392292 3。890659
。。。。。。。。。。
#include <stdio.h>
#include <math.h>
#define PI 3.1415926
main()
{long float h1a,h1b,dec1a,dec1b,gha1a,gha1b,h1,dec1,gha1,
h2a,h2b,dec2a,dec2b,gha2a,gha2b,h2,dec2,gha2,
h3a,h3b,dec3a,dec3b,gha3a,gha3b,h3,dec3,gha3;
printf("please input h1:");
scanf("%lf%lf",&h1a,&h1b);
printf("please input dec1:");
scanf("%lf%lf",&dec1a,&h1b);
printf("please input gha1:");
scanf("%lf%lf",&gha1a,&gha1b);
printf("please input h2:");
scanf("%lf%lf",&h2a,&h2b);
printf("please input dec2:");
scanf("%lf%lf",&dec2a,&h2b);
printf("please input gha2:");
scanf("%lf%lf",&gha2a,&gha2b);
printf("please input h3:");
scanf("%lf%lf",&h3a,&h3b);
printf("please input dec3:");
scanf("%lf%lf",&dec3a,&h3b);
printf("please input gha3:");
scanf("%lf%lf",&gha3a,&gha3b);
h1=h1a*PI/180+h1b*PI/10800;
dec1=dec1a*PI/180+dec1b*PI/10800;
gha1=gha1a*PI/180+gha1b*PI/10800;
h2=h2a*PI/180+h2b*PI/10800;
dec2=dec2a*PI/180+dec2b*PI/10800;
gha2=gha2a*PI/180+gha2b*PI/10800;
h3=h3a*PI/180+h3b*PI/10800;
dec3=dec3a*PI/180+dec3b*PI/10800;
gha3=gha3a*PI/180+gha3b*PI/10800;
printf("\n");
printf("%lf %lf %lf\n",h1,dec1,gha1);
printf("%lf %lf %lf\n",h2,dec2,gha2);
printf("%lf %lf %lf\n",h3,dec3,gha3);
}请各位高手指点指点 展开
h1=31°32′.5 Dec1 =22°28′.6S GHA1 =222°55′.1
h2=32°39′.0 Dec2 =19°12′.0N GHA2 =295°50′.3
h3=63°18′.4 Dec3 =45°15′.9N GHA3 =200°05′.8
结果为
0.532733 -1.85003940070e+297 3.890659
0.561996 0.331613 5.163353
1.104183 0.7853398 3.492346
第一个结果就错了,本来结果为0。55056 -0。392292 3。890659
。。。。。。。。。。
#include <stdio.h>
#include <math.h>
#define PI 3.1415926
main()
{long float h1a,h1b,dec1a,dec1b,gha1a,gha1b,h1,dec1,gha1,
h2a,h2b,dec2a,dec2b,gha2a,gha2b,h2,dec2,gha2,
h3a,h3b,dec3a,dec3b,gha3a,gha3b,h3,dec3,gha3;
printf("please input h1:");
scanf("%lf%lf",&h1a,&h1b);
printf("please input dec1:");
scanf("%lf%lf",&dec1a,&h1b);
printf("please input gha1:");
scanf("%lf%lf",&gha1a,&gha1b);
printf("please input h2:");
scanf("%lf%lf",&h2a,&h2b);
printf("please input dec2:");
scanf("%lf%lf",&dec2a,&h2b);
printf("please input gha2:");
scanf("%lf%lf",&gha2a,&gha2b);
printf("please input h3:");
scanf("%lf%lf",&h3a,&h3b);
printf("please input dec3:");
scanf("%lf%lf",&dec3a,&h3b);
printf("please input gha3:");
scanf("%lf%lf",&gha3a,&gha3b);
h1=h1a*PI/180+h1b*PI/10800;
dec1=dec1a*PI/180+dec1b*PI/10800;
gha1=gha1a*PI/180+gha1b*PI/10800;
h2=h2a*PI/180+h2b*PI/10800;
dec2=dec2a*PI/180+dec2b*PI/10800;
gha2=gha2a*PI/180+gha2b*PI/10800;
h3=h3a*PI/180+h3b*PI/10800;
dec3=dec3a*PI/180+dec3b*PI/10800;
gha3=gha3a*PI/180+gha3b*PI/10800;
printf("\n");
printf("%lf %lf %lf\n",h1,dec1,gha1);
printf("%lf %lf %lf\n",h2,dec2,gha2);
printf("%lf %lf %lf\n",h3,dec3,gha3);
}请各位高手指点指点 展开
2个回答
展开全部
你的程序没有输入"秒",那么第一个算出来是0.550360,我感觉这个就是正确的
另外,你的scanf里面%lf和%lf之间是连写的,所以输入时31 32这些数据中间不能用逗号分开,只能用空格.
另外,你的scanf里面%lf和%lf之间是连写的,所以输入时31 32这些数据中间不能用逗号分开,只能用空格.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询