角度(度分秒)的四则运算 您所在的位置:网站首页 度分秒计算器下载 角度(度分秒)的四则运算

角度(度分秒)的四则运算

2024-01-04 19:46| 来源: 网络整理| 查看: 265

角度(度分秒)的四则运算

在测量计算(如闭合导线坐标计算),我们可能需要计算比较多的角度。数学中,角度的度与分、分与秒之间一律采用六十进制,完全通过笔算耗时耗力,还容易算错。下面用C语言知识编写一个简单的程序,来实现角度的四则运算。

#include #include typedef struct angle { int degree; int minute; int second; }ANGLE; void decrease(ANGLE a[], int i); void add(ANGLE a[], int i); void multiply(ANGLE a[], int i, int j); void divide(ANGLE a[], int i, int j); int main() { do { int i = 0, k, j = 0; float degree = 0; char operation[25]; ANGLE a[25] = {0}; printf("本程序可实现角度(度/分/秒)的四则运算,输入时角度的度、分、秒间以一个空格隔开\n"); printf("角度 %d:",i+1); scanf("%d %d %d",&a[i].degree, &a[i].minute, &a[i].second); getchar(); printf("运算符:"); scanf("%c",&operation[i]); do { if(operation[i] == '+' || operation[i] == '-') { i++; printf("角度 %d:",i+1); scanf("%d %d %d",&a[i].degree, &a[i].minute, &a[i].second); getchar(); printf("运算符:"); scanf("%c",&operation[i]); } else if(operation[i] == '*') { printf(" 乘数:"); scanf("%d", &j); getchar(); printf("运算符:"); scanf("%c",&operation[i+1]); } else if(operation[i] == '/') { printf(" 除数:"); scanf("%d", &j); getchar(); printf("运算符:"); scanf("%c",&operation[i+1]); } }while(operation[i] != '=' && operation[i+1] != '='); for(k = 0; k add(a, k+1); } else if(operation[k] == '-') { decrease(a, k+1); } else if(operation[k] == '*') { multiply(a, k, j); } else if(operation[k] == '/') { divide(a, k, j); } else if(operation[k] != '-' && operation[k] != '+' && operation[k] != '=' && operation[k] != '/' && operation[k] != '*') { printf("请输入正确的运算符!\n"); } } if(a[i].degree printf("结果为:%d°%d′%d″\n",a[i].degree, a[i].minute, a[i].second); } degree = (float)a[i].degree + (float)a[i].minute / 60 + (float)a[i].second / 3600; printf("换算为:%f°\n", degree); getchar(); getchar(); }while(1); } void add(ANGLE a[], int i) { long s1, s2, s3 = 0; s1 = a[i-1].degree*60*60 + a[i-1].minute*60 + a[i-1].second; s2 = a[i].degree*60*60 + a[i].minute*60 + a[i].second; s3 = s1 + s2; a[i].degree = s3 / 3600; a[i].minute = (s3 - (a[i].degree) * 3600) / 60; a[i].second = s3 % 60; } void decrease(ANGLE a[], int i) { long s1, s2, s3 = 0; s1 = a[i-1].degree*60*60 + a[i-1].minute*60 + a[i-1].second; s2 = a[i].degree*60*60 + a[i].minute*60 + a[i].second; s3 = s1 - s2; a[i].degree = s3 / 3600; a[i].minute = (s3 - (a[i].degree) * 3600) / 60; a[i].second = s3 % 60; } void multiply(ANGLE a[], int i, int j) { long s1, s3 = 0; s1 = a[i].degree*60*60 + a[i].minute*60 + a[i].second; s3 = s1 * j; a[i].degree = s3 / 3600; a[i].minute = (s3 - (a[i].degree) * 3600) / 60; a[i].second = s3 % 60; } void divide(ANGLE a[], int i, int j) { long s1, s3 = 0; s1 = a[i].degree*60*60 + a[i].minute*60 + a[i].second; s3 = s1 / j; a[i].degree = s3 / 3600; a[i].minute = (s3 - (a[i].degree) * 3600) / 60; a[i].second = s3 % 60; }

code blocks中运行示例 在这里插入图片描述 如果单次计算的角度多于25个,只需更改这两行代码,改变数组的大小。

char operation[25]; ANGLE a[25] = {0};


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有