求一段C小程序关于度分秒.转换

2024-12-14 17:37:58
推荐回答(5个)
回答1:

#include
int main(int argc, char *argv[])
{
int a,b,c;
double d;
printf("输入度分秒(格式:10°39'59''):");
scanf("%d°%d\'%d\'\'",&a,&b,&c);
d = (a + b/60.0 + c/3600.0);
printf("%d°%d\'%d\'\' = %lf°\n",a,b,c,d);
return 0;
}
/*
输入度分秒(格式:10°39'59''):10°39'59''
10°39'59'' = 10.666389°
*/

回答2:

# include
# include
void yp(char a[])
{
int i=0;
double num,b=0,c=0,d=0;
char *q,*j,*k;
q=strstr(a,"°");
j=strstr(a,"′");
k=strstr(a,"″");
for(;&a[i]!=q;i++)
b=b*10+a[i]-48;
for(i=i+2;&a[i]!=j;i++)
c=c*10+a[i]-48;
for(i=i+2;&a[i]!=k;i++)
d=d*10+a[i]-48;
num=b+c/60+d/3600;
printf("转化成度值为:%lf",num);
printf("°\n");
}
int main()
{
char a[15];
printf("请用输入法,输入标准°′″\n");
printf("请输入数据如( 10°39′59″):");
gets(a);
yp(a);
return 0;
}

你的结果是错的

回答3:

程序如下,不明白追问吧!
依次输入10 39 59输出10.66388
#include
#include
void main()
{
int du,fen,miao;
float result;
printf("度分秒格式转为度格式\n");
printf("请输入度数\n");
scanf("%d",&du);
printf("请输入分数\n");
scanf("%d",&fen);
printf("请输入秒数\n");
scanf("%d",&miao);
result=(float)(fen*60+miao)/3600+du;
printf("转化后的度数为:%f\n",result);
}

回答4:

void convert(char* from, char* to) {
int a = 0, b = 0, c = 0;

char buff[8];
char *p1 = from;
char *p2 = strstr(p1, "°"); // 不太确定"°"是一个字节还是多个字节,所以这样写保险些。
if (p2 != NULL) {
strncpy(buff, p1, p2-p1);
a = atoi(buff);
p1 = p2 + strlen("°");
}
p2 = strchr(p1, '\'');

if (p2 != NULL) {
strcpy(buff, p1, p2-p1);
b = atoi(buff);
p1 = p2 + 1;
}
p2 = strchr(p1, '"');
if (p2 != NULL) {
strcpy(buff, p1, p2-p1);
b = atoi(buff);
p1 = p2 + 1;
}
sprintf(to, "%f°", (c/60.0 + b) / 60.0 + a);
return;
}

回答5:

#include

int main() //xcode :int main() vc: main()

{

int a,b,c;

double d;

printf("please input degree (e.g.:10°39'59''): \n"); //display the tooltip

scanf("%d°%d'%d''",&a,&b,&c); //input degree

d = (a + b/60.0 + c/3600.0); //transition

printf("The consequenceis:%d°%d'%d'' = %lf°\n",a,b,c,d); //output the consequence

}