當前位置:首頁 » 編程語言 » 地球c語言代碼
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

地球c語言代碼

發布時間: 2022-12-26 18:42:51

Ⅰ 已知地球半徑,用c語言編寫程序求同一緯度不同經度的兩地的距離

#include<stdio.h>
#include<math.h>
int main(void)
{
float r, w, j, pi;//r表示半徑,w表示緯度,j表示經度差,緯度和經度的單位都是度,pi表示圓周率
pi=2.0*asin(1.0);
printf("請輸入地球半徑:r= ");
scanf("%f",&r);
printf("請輸入緯度 w= ");
scanf("%f",&w);
printf("請輸入兩個地點的經度差 j= ");
scanf("%f",&j);
printf("這兩個地方的距離里為: %lf\n",r*sin( (90.0-w)/180.0*pi )*( j/180.0*pi ) );
}

Ⅱ 求C語言程序代碼

// Microsoft Visual C++ 2010學習版


#include <stdio.h>


double add_thickness(double *thickness_ptr, int *times_ptr)

{

*thickness_ptr *= 2;


if (*times_ptr == 1)

{

return *thickness_ptr;

}

(*times_ptr)--;


return add_thickness(thickness_ptr, times_ptr);

}


int main()

{

double thickness = 0.006; // 0.006cm

int times = 43;


printf("設定紙張厚度:%f cm ", thickness);

printf("算出地月距離:%f cm ", add_thickness(&thickness,&times));

printf("算出地月距離:%f km ", thickness / 1000 / 100);


// 地月距離

double distance = (double)386000 * 1000 * 100; // cm

// 操作43次

for (int i = 1; i <= 43; i++)

{

distance /= 2;

}

printf("紙張厚度應為:%f cm ", distance);


// 檢驗add_thickness()正確性

times = 43;

printf("按上述厚度,地月距離:%f km ", add_thickness(&distance,&times) / 1000 / 100);


return 0;

}

---

若紙厚度0.006cm,按題操作43次,紙高度遠大於地月距離386000公里!

若紙厚度0.004388cm,按題操作43次,紙高度等於地月距離386000公里。

程序執行結果:

Ⅲ 求高手幫我做一下這道c語言編程題目

#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;
}

Ⅳ 月球圍繞地球,地球圍繞太陽的C語言代碼

A、當地球繞太陽公轉從B到C,太陽直射點由赤道向南回歸線移動,淮安的白晝越來越短,故不符合題意;B、當地球繞太陽公轉從B到C,太陽直射點由赤道向南回歸線移動,淮安的西北季風越來強盛,故不符合題意;C、當地球繞太陽公轉從B到C,太陽直射點由赤道向南回歸線移動,時間從9月23日到12月22日,梅雨時間一般在6月下旬到7月上旬,故不符合題意;D、當地球繞太陽公轉從B到C,太陽直射點由赤道向南回歸線移動,淮安的黑夜越來越長,故正確.故選:D.

Ⅳ 已知地球的平均半徑為6371.393千米,假設在地球的某一緯度上,有兩個處於不同經度的點A、B,用C語言編程

float 數 只能輸出小數點後六位..用 double, %lf定義數和輸出數

Ⅵ 地球與月球之間的距離大約是238857英里寫C語言程序在屏幕上顯示出地球與月球之間的大約是多少公里

#include<stdio.h>
main()
{
doublea=238857;
printf("%lf",a*1.609);
}

如圖所示,望採納。。。。。。

Ⅶ 已知地球任意兩點,求兩點間的直線距離和球面距離用c語言

這段代碼可以達到你的目的。注釋和其他有關信息自己添加。
//#include "stdafx.h"//vc++6.0加上這一行.
#include "stdio.h"
#include "math.h"
void main(void){
double x1,x2,x,r=6378.137,pai=3.1415926;
printf("Type 2 longitudes\n");
scanf("%lf%lf",&x1,&x2);
while(x1<0) x1+=360;
while(x2<0) x2+=360;
if((x=fabs(x1-x2))>180) x=360-x;
x=x/360*2*pai;
printf("The linear distance is %f(km)\n",2*r*sin(x/2));
printf("The arc length is %f(km)\n",r*x);
}

Ⅷ 利用日期、經緯度求日出日落時間 C語言程序代碼

#definePI3.1415926

#include<math.h>

#include<iostream>

usingnamespacestd;


intdays_of_month_1[]={31,28,31,30,31,30,31,31,30,31,30,31};

intdays_of_month_2[]={31,29,31,30,31,30,31,31,30,31,30,31};

longdoubleh=-0.833;

//定義全局變數


voidinput_date(intc[]){

inti;

cout<<"Enterthedate(form:20090310):"<<endl;

for(i=0;i<3;i++){

cin>>c[i];

}

}

//輸入日期


voidinput_glat(intc[]){

inti;

cout<<"Enterthedegreeoflatitude(range:0°-60°,form:404040(means40°40′40″)):"<<endl;

for(i=0;i<3;i++){

cin>>c[i];

}

}

//輸入緯度


voidinput_glong(intc[]){

inti;

cout<<"Enterthedegreeoflongitude(westisnegativ,form:404040(means40°40′40″)):"<<endl;

for(i=0;i<3;i++){

cin>>c[i];

}

}

//輸入經度


intleap_year(intyear){

if(((year%400==0)||(year%100!=0)&&(year%4==0)))return1;

elsereturn0;

}

//判斷是否為閏年:若為閏年,返回1;若非閏年,返回0


intdays(intyear,intmonth,intdate){

inti,a=0;

for(i=2000;i<year;i++){

if(leap_year(i))a=a+366;

elsea=a+365;

}

if(leap_year(year)){

for(i=0;i<month-1;i++){

a=a+days_of_month_2[i];

}

}

else{

for(i=0;i<month-1;i++){

a=a+days_of_month_1[i];

}

}

a=a+date;

returna;

}

//求從格林威治時間公元2000年1月1日到計算日天數days


longdoublet_century(intdays,longdoubleUTo){

return((longdouble)days+UTo/360)/36525;

}

//求格林威治時間公元2000年1月1日到計算日的世紀數t


longdoubleL_sun(longdoublet_century){

return(280.460+36000.770*t_century);

}

//求太陽的平黃徑


longdoubleG_sun(longdoublet_century){

return(357.528+35999.050*t_century);

}

//求太陽的平近點角


longdoubleecliptic_longitude(longdoubleL_sun,longdoubleG_sun){

return(L_sun+1.915*sin(G_sun*PI/180)+0.02*sin(2*G_sun*PI/180));

}

//求黃道經度


longdoubleearth_tilt(longdoublet_century){

return(23.4393-0.0130*t_century);

}

//求地球傾角


longdoublesun_deviation(longdoubleearth_tilt,longdoubleecliptic_longitude){

return(180/PI*asin(sin(PI/180*earth_tilt)*sin(PI/180*ecliptic_longitude)));

}

//求太陽偏差


longdoubleGHA(longdoubleUTo,longdoubleG_sun,longdoubleecliptic_longitude){

return(UTo-180-1.915*sin(G_sun*PI/180)-0.02*sin(2*G_sun*PI/180)+2.466*sin(2*ecliptic_longitude*PI/180)-0.053*sin(4*ecliptic_longitude*PI/180));

}

//求格林威治時間的太陽時間角GHA


longdoublee(longdoubleh,longdoubleglat,longdoublesun_deviation){

return180/PI*acos((sin(h*PI/180)-sin(glat*PI/180)*sin(sun_deviation*PI/180))/(cos(glat*PI/180)*cos(sun_deviation*PI/180)));

}

//求修正值e


longdoubleUT_rise(longdoubleUTo,longdoubleGHA,longdoubleglong,longdoublee){

return(UTo-(GHA+glong+e));

}

//求日出時間


longdoubleUT_set(longdoubleUTo,longdoubleGHA,longdoubleglong,longdoublee){

return(UTo-(GHA+glong-e));

}

//求日落時間


longdoubleresult_rise(longdoubleUT,longdoubleUTo,longdoubleglong,longdoubleglat,intyear,intmonth,intdate){

longdoubled;

if(UT>=UTo)d=UT-UTo;

elsed=UTo-UT;

if(d>=0.1){

UTo=UT;

UT=UT_rise(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo))))));

result_rise(UT,UTo,glong,glat,year,month,date);

}

returnUT;

}

//判斷並返回結果(日出)


longdoubleresult_set(longdoubleUT,longdoubleUTo,longdoubleglong,longdoubleglat,intyear,intmonth,intdate){

longdoubled;

if(UT>=UTo)d=UT-UTo;

elsed=UTo-UT;

if(d>=0.1){

UTo=UT;

UT=UT_set(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo))))));

result_set(UT,UTo,glong,glat,year,month,date);

}

returnUT;

}

//判斷並返回結果(日落)


intZone(longdoubleglong){

if(glong>=0)return(int)((int)(glong/15.0)+1);

elsereturn(int)((int)(glong/15.0)-1);

}

//求時區


voidoutput(longdoublerise,longdoubleset,longdoubleglong){

if((int)(60*(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<10)

cout<<"Thetimeatwhichthesunrisesis"<<(int)(rise/15+Zone(glong))<<":0"<<(int)(60*(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<<". ";

elsecout<<"Thetimeatwhichthesunrisesis"<<(int)(rise/15+Zone(glong))<<":"<<(int)(60*(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<<". ";

if((int)(60*(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<10)

cout<<"Thetimeatwhichthesunsetsis"<<(int)(set/15+Zone(glong))<<":"<<(int)(60*(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<<". ";

elsecout<<"Thetimeatwhichthesunsetsis"<<(int)(set/15+Zone(glong))<<":"<<(int)(60*(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<<". ";

}

//列印結果intmain(){

longdoubleUTo=180.0;

intyear,month,date;

longdoubleglat,glong;

intc[3];

input_date(c);

year=c[0];

month=c[1];

date=c[2];

input_glat(c);

glat=c[0]+c[1]/60+c[2]/3600;

input_glong(c);

glong=c[0]+c[1]/60+c[2]/3600;

longdoublerise,set;

rise=result_rise(UT_rise(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))))),UTo,glong,glat,year,month,date);

set=result_set(UT_set(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))))),UTo,glong,glat,year,month,date);

output(rise,set,glong);

system("pause");

return0;

}