c语言编程计算两度分秒的加减
时间: 2023-10-09 16:11:11 浏览: 56
可以使用以下代码计算两个角度的加减:
```c
#include <stdio.h>
#include <math.h>
// 将角度转化为度分秒格式
void convertToDMS(double angle, int *degrees, int *minutes, double *seconds) {
*degrees = (int)angle;
double decimal = angle - *degrees;
*minutes = (int)(decimal * 60);
*seconds = (decimal - *minutes / 60.0) * 3600;
}
// 将度分秒格式转化为角度
double convertToAngle(int degrees, int minutes, double seconds) {
return degrees + minutes / 60.0 + seconds / 3600.0;
}
int main() {
double angle1, angle2;
int degrees1, degrees2, minutes1, minutes2;
double seconds1, seconds2;
printf("Enter the first angle in degrees, minutes, and seconds:\n");
scanf("%d %d %lf", °rees1, &minutes1, &seconds1);
angle1 = convertToAngle(degrees1, minutes1, seconds1);
printf("Enter the second angle in degrees, minutes, and seconds:\n");
scanf("%d %d %lf", °rees2, &minutes2, &seconds2);
angle2 = convertToAngle(degrees2, minutes2, seconds2);
// 计算角度和
double sum = angle1 + angle2;
printf("The sum of the angles is: %f degrees\n", sum);
// 计算角度差
double diff = fabs(angle1 - angle2);
printf("The difference between the angles is: %f degrees\n", diff);
return 0;
}
```
该程序首先将输入的两个角度转换为度分秒格式,然后将它们转换为角度进行计算。最终输出角度和和角度差。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)