#define PAI 3.14//定义圆周率
int main(){
float r = 0
scanf("%f",&r) //输入半慧橘码径,因为是小数,所以用FLOAT型接收
printf("共有约%ld亿吨",5.52*PAI*4/3*r*r*r*10)//数太大了,一个长前哪整形伍滚都装不下,只能标称亿吨
return 0
}
#include <stdio.h>#include <math.h>
#define PI 3.14 //圆周率
#define RAD 6371//地扰颂球半径
int main()
{
double peri //小圆周长
double rad//小圆半径
double length
double longitudeA , longitudeB//A,B经度
double latitude //A,B纬宏李脊度
double temp
printf("请输入A和B的经度:\n")
scanf("%lf%lf",&longitudeA,&longitudeB)
printf("请输入A和B的纬度蔽渗:\n")
scanf("%lf",&latitude)
rad = cos(latitude) * RAD
peri = 2*PI*rad
temp = longitudeA - longitudeB
length = (temp >0 ? temp : (temp*-1))/360 * peri
printf("A和B的距离是:%f千米\n",length)
return 0
}
根据你的春亩基题目写的
#include <iostream>
#include <string>
using namespace std
#define EARTH_RADIUS 6371.393
#define PI 3.14159
int main(int argc,char ** argv)
{
while(1)
{
char szInput[128]
string strInput
string strTmp
char szTmp[128]
string::size_type Index
float LatLongitude[3]={0} //经纬度
float Radius
float ArcLen //弧长
float ChordLen //弦长
float LonDiff //圆心角
int i=0
cout<<"-----------------------------------------------"<<endl
cout<<"请输入经纬度"<<endl
cin.clear()
cin.sync()
cin.get(szInput,sizeof(szInput))
strInput=szInput
while((Index=strInput.find(" ")) != string::npos)
{
strTmp=strInput.substr(0,Index)
_snprintf(szTmp,sizeof(szTmp),"%s",strTmp.c_str())
sscanf(szTmp,"%f",&(LatLongitude[i]))
strInput=strInput.substr(Index+1)
i++
}
_snprintf(szTmp,sizeof(szTmp),"耐档%s",strInput.c_str())
sscanf(szTmp,"%f",&(LatLongitude[i]))
if(LatLongitude[0]>90 || LatLongitude[0]<-90)
{
cout<<"输入纬度有误"<<endl
continue
}
if(LatLongitude[1]<-180 || LatLongitude[1]>180 || LatLongitude[2]<-180 || LatLongitude[2]>180)
{
cout<<"输入经度有误"<<endl
continue
}
Radius=EARTH_RADIUS*sin((90-LatLongitude[0])/180*PI)
if(LatLongitude[2]>LatLongitude[1])
{
LonDiff=LatLongitude[2]-LatLongitude[1]
}
else
{
LonDiff=LatLongitude[1]-LatLongitude[2]
}
if(LonDiff>180)
{
LonDiff=360-LonDiff
}
ChordLen=Radius*sin(LonDiff/2/180*PI)*2
ArcLen=2*Radius*PI*(LonDiff/360)
cout<<"两点之间的弦长:"<<ChordLen<<"千米"<<endl
cout<<扒谨"弦长所对应的圆心角:"<<LonDiff<<"度"<<endl
cout<<"两点之间的劣弧长:"<<ArcLen<<"千米"<<endl
}
return 0
}
运行
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)