⑴ c語言的作業,求救,怎麼做啊
#include<stdio.h>
int main()
{
int a[4],b[4];
int k=1,j=1,x,y,t;
scanf("%d%d",&x,&y);
while(x!=0)
{
a[k++]=x%10;//把x的各個位提取出來
x/=10;
}
while(y!=0)
{
b[j++]=y%10;//把y的各個提取出來
y/=10;
}
t=a[2];
a[2]=b[2];//十位交換
b[2]=t;
for(int i=3;i>=1;i--)
{
printf("%d",a[i]);
}
printf(" ");
for(int i=3;i>=1;i--)
{
printf("%d",b[i]);
}
return 0;
}
⑵ 怎樣用c語言編寫下面這個問題,困擾我好多天了:
解題思路是這樣的:
1、先計算兩城市的徑度間隔α。 因為東經180度和西經180度重合,所以只要兩城市在同一側(如都是東經)就取差值;在不同側 就取和,但和如超過180度,就要用360度來減,才是實際的經度差α。
2、再求出兩城市(A、B)與地心連線之間的夾角β。【估計你被困在這里】
如果A、B在赤道上,那麼β就是經度差α,而如果都在極點,β就等於0,在此之間呢?β等於α乘以緯度的餘弦,即 β=α*cos(緯度值) 。推理過程從略,自己去想哈。
3、地球周長*β/360 就是兩地的距離啦
代碼你自己整吧,應該木有問題吧?
⑶ C語言實現經緯度的轉換
辦法很多,三維字元數組,指針字元數組都可以,分別保存字元串到數組元素,最後以%s輸出即可。
我來寫個最簡單的
#include "stdafx.h"
#include "stdlib.h"
#include "string.h"
void explain_NS(char * str)
{
char tmp_ca[30] = "";
if(str[0] == 'N')
strcpy(tmp_ca,"北緯");
else
strcpy(tmp_ca,"南緯");
char *p = tmp_ca;
while(*p) p++;
strncpy(p, str+1, 2);
p += 2;
*p = 176;
p ++;
strncpy(p,str+3,2);
p += 2;
*p = 39;
p++;
strncpy(p, str+6,5);
p += 5;
*p = 34;
printf("%s\n",tmp_ca);
}
void explain_EW(char * str)
{
char tmp_ca[30] = "";
if(str[0] == 'E')
strcpy(tmp_ca,"東經");
else
strcpy(tmp_ca,"西經");
char *p = tmp_ca;
while(*p) p++;
strncpy(p, str+1, 3);
p += 3;
*p = 176;
p ++;
strncpy(p,str+4,2);
p += 2;
*p = 39;
p++;
strncpy(p, str+7,5);
p += 5;
*p = 34;
printf("%s\n",tmp_ca);
}
int _tmain(int argc, _TCHAR* argv[])
{
char ca[30] = "N3018.93661";
char cb[30] = "E12022.88281";
explain_NS(ca);
explain_EW(cb);
system("pause");
return 0;
}
⑷ 如何根據給定經緯度進行分區 c語言實現
代碼如下,VS2012親測,可以運行,給你注釋的很清楚了,不懂的地方可以問我。
#include <windows.h>
#include <stdio.h>
int main()
{
int DSLength = GetLogicalDriveStrings(0,NULL);
//通過GetLogicalDriveStrings()函數獲取所有驅動器字元串信息長度。
char* DStr = new char[DSLength];//用獲取的長度在堆區創建一個c風格的字元串數組
GetLogicalDriveStrings(DSLength,(LPTSTR)DStr);
//通過GetLogicalDriveStrings將字元串信息復制到堆區數組中,其中保存了所有驅動器的信息。
int DType;
int si=0;
for(int i=0;i<DSLength/4;++i)
//為了顯示每個驅動器的狀態,則通過循環輸出實現,由於DStr內部保存的數據是A:\NULLB:\NULLC:\NULL,這樣的信息,所以DSLength/4可以獲得具體大循環范圍
{
char dir[3]={DStr[si],':','\\'};
//cout<<dir;
DType = GetDriveType((LPCWSTR)DStr+i*4);
//GetDriveType函數,可以獲取驅動器類型,參數為驅動器的根目錄
if(DType == DRIVE_FIXED)
{
printf("%c",*dir);
printf("硬碟\n");
}
si+=4;
}
system("pause");//
return 1;
}
⑸ C語言知道經緯度求兩地距離的題目,求高手指點哪裡錯了,對了再加分
最後的計算s的公式有問題,因為反餘弦函數y=arccosx中,y的取值范圍只能是-π/2 ≤ y ≤ π/2,而地球上兩點間的夾角明顯在0到180°之間,所以這個地方你還應該加上角度判斷語句,另外你的R的單位是km,最後的結果頁應該是km。
⑹ 已知某地點的精度λ,試求它所在的6°帶與3°的帶號及中央子午線的經度是多少
若已知某點的經度為λ,則該點的6º帶的帶號N由下式計算:
N=int(λ/6)+1 (int為取整的意思)
中央子午線經度 Ln=6°N-3°
若已知某點的經度為L,則該點所在3º帶的帶號按下式計算:
n=L/3 (四捨五入)
中央子午線經度 Ln=3°n
⑺ c語言設計問題
#include<stdio.h>
#include<math.h>
#definePI3.141592
main()
{
doublea,b,c,d,s,r; /*a表示緯度,bc表示經度*/
r=6371.00;
printf("請輸入緯度a=");
scanf("%lf",&a);
d=cosh(a)*r; /*d表示此緯度上的半徑*/
printf("請輸入兩地經度(東經為正,西經為負)b=,c=");
scanf("%lf%lf",&b,&c);//加了,
s=fabs(b-c)/360*2*PI*d;
printf("%lf",s);
}
//我把%f改成了%lf
//你運行一下試一試
//怎麼,有什麼問題
⑻ C語言中怎麼表示經緯度呢
提供一思路,僅參考:
參照坐標系點的表示法
a(x,y)
⑼ 求解C語言編程
已知兩地的經度分別為σ1、σ2,緯度分別為φ1、φ2,求兩地最近距離的公式為:
S=2πRθ/360° (1)
其中θ可由下面的式子求得:
[sin(θ/2)]^2=[sin(φ1-φ2)/2]^2+[sin(σ2-σ1)/2]^2cosφ1cosφ2 (2)
註:1、式中S為球面上任意兩點的最短距離(球面距離);
2、θ為兩點間的張角,在運用(2)式求θ時,緯度φ和經度σ本身有正負號,通常北緯正,南緯負;東經正,西經負。
3、因不會用上下標,所以式中^2指平方; cosφ1cosφ2、σ2-σ1 、φ1-φ2中的1和和2為下標。
我想你的問題是不知道公式,知道公式後就是C語言做個算術題,這個不用我教了吧。
⑽ 利用日期、經緯度求日出日落時間 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;
}