当前位置: 首页 > news >正文

网站建立需要什么168推广网

网站建立需要什么,168推广网,企业网站模板下载,郴州网站建设软件定制开发平台00 两种可行方法分别是: 使用数组存储每一位数据并进行进位运算:通过将大数按位拆分成数组,然后实现逐位加法、进位等操作。使用符号变量进行计算:将数值分成低位和高位,分别用符号变量进行计算。 01:使用…

00 两种可行方法分别是:

  1. 使用数组存储每一位数据并进行进位运算:通过将大数按位拆分成数组,然后实现逐位加法、进位等操作。
  2. 使用符号变量进行计算:将数值分成低位和高位,分别用符号变量进行计算。

01:使用数组存储数据大小并处理进位

在这种方法中,我们将数值拆分成若干个位数(数组中的元素),并通过数组存储每一位数字,手动处理进位。

假设我们要处理的数值是存款金额 principal 和最终计算的利息,数值可能非常大,需要使用一个数组来按位存储。每个数组元素存储一个数字(从0到9),并手动实现加法和进位。

代码实现:
#include <reg52.h>
#include <math.h>
#include <stdio.h>#define MAX_DIGITS 20  // 数字的最大位数// 复利计算函数,采用逐位运算
void multiply_by_factor(int* number, double factor) {double carry = 0;  // 用于存储进位for (int i = 0; i < MAX_DIGITS; i++) {double digit_value = number[i] * factor + carry;number[i] = (int)digit_value % 10;  // 当前位carry = digit_value / 10;  // 进位}
}// 打印数组中的大数
void print_large_number(int* number) {int i = MAX_DIGITS - 1;while (i >= 0 && number[i] == 0) {i--;  // 去掉前导零}if (i == -1) {uart_send_char('0');  // 如果数组全是0,则显示0} else {while (i >= 0) {uart_send_char(number[i] + '0');i--;}}
}// 使用字符数组存储和计算复利
void calculate_large_interest(double principal, double rate, int years) {int large_number[MAX_DIGITS] = {0};  // 数字存储数组int i;// 将存款金额(principal)转换为数组形式for (i = MAX_DIGITS - 1; i >= 0; i--) {large_number[i] = (int)principal % 10;  // 存储个位数principal /= 10;  // 除以10,获得下一个位}// 计算复利double factor = 1 + rate / 100;for (i = 0; i < years; i++) {multiply_by_factor(large_number, factor);}// 打印结果print_large_number(large_number);
}void main() {double principal = 1000.00;  // 假设存款金额为1000元double rate = 3.5;           // 假设年利率为3.5%int years = 5;               // 假设存款年数为5年uart_init();  // 初始化串口// 计算并打印复利结果calculate_large_interest(principal, rate, years);
}
  • large_number[MAX_DIGITS]:用于存储存款金额的每一位数字,MAX_DIGITS 定义了存储的最大位数。
  • multiply_by_factor():该函数逐位计算大数与利率的乘积,并处理每一位的进位。通过逐位相乘并累加进位来实现复利计算。
  • print_large_number():将存储的大数数组打印到串口。
  • calculate_large_interest():这是主计算函数,首先将本金 principal 转换为大数数组,然后逐年计算复利。

02:使用符号变量(高位和低位分别存储)

这种方法相对简单,通过将数值拆分为低位和高位两部分来计算。符号变量可以帮助处理较大范围的数值。虽然不如数组方法灵活,但可以应对一些场景。

代码实现:

#include <reg52.h>
#include <stdio.h>
#include <math.h>#define MAX_INT 0xFFFF  // 假设使用16位符号变量// 定义一个结构体用于存储大数
typedef struct {unsigned int low;   // 低位unsigned int high;  // 高位
} BigNumber;// 将两个整数合并成一个大数
BigNumber multiply_big_number(BigNumber num, double factor) {double result_low = num.low * factor;double result_high = num.high * factor;// 处理低位进位unsigned int new_low = (unsigned int)result_low;unsigned int carry = (unsigned int)(result_low / MAX_INT);// 处理高位和进位unsigned int new_high = (unsigned int)(result_high + carry);BigNumber result = { new_low, new_high };return result;
}// 打印大数
void print_big_number(BigNumber num) {uart_send_char((num.high >> 8) & 0xFF);  // 打印高位字节uart_send_char(num.high & 0xFF);uart_send_char((num.low >> 8) & 0xFF);   // 打印低位字节uart_send_char(num.low & 0xFF);
}void calculate_large_interest(double principal, double rate, int years) {// 初始化大数BigNumber principal_big = { (unsigned int)(principal), 0 };// 计算复利BigNumber result = principal_big;double factor = 1 + rate / 100;for (int i = 0; i < years; i++) {result = multiply_big_number(result, factor);}// 打印结果print_big_number(result);
}void main() {double principal = 1000.00;  // 假设存款金额为1000元double rate = 3.5;           // 假设年利率为3.5%int years = 5;               // 假设存款年数为5年uart_init();  // 初始化串口// 计算并打印复利结果calculate_large_interest(principal, rate, years);
}

解释:

  • BigNumber 结构体:用于存储一个大数的低位和高位。
  • multiply_big_number():将大数与利率相乘,并处理低位和高位的进位。
  • print_big_number():将大数通过串口输出,打印低位和高位。
  • calculate_large_interest():计算复利的主函数,初始化本金的高低位数据,逐年进行复利计算。

 其他需要注意的问题:

 2. 51内存大小限制

需减少数组大小和double的使用

同时注意char 类型数组需要以'\0'结尾

3.复利年数过多时,使用数组单个计算理论可行,但程序疑似跑飞

4.无法使用#include <math.h>

pow((1 + rate / 100), years)

总结:

  1. 方案1(数组存储和逐位计算):适用于处理更大范围的数值,灵活性更高,可以根据需要扩展位数。
  2. 方案2(符号变量存储):相对简单,通过高低位分离来处理较大的数值,但计算灵活性较差。

两种方法各有优劣,选择哪一种方法取决于系统资源和所需的计算精度。如果存储空间和计算能力有限,使用符号变量(方案2)可能更为高效。如果需要处理更大范围的数值或更高精度,使用数组存储和逐位计算(方案1)会更适合


文章转载自:
http://wanjiahexahydroxy.sqLh.cn
http://wanjiaoverarch.sqLh.cn
http://wanjiabiquadrate.sqLh.cn
http://wanjiaeruca.sqLh.cn
http://wanjiatripolitania.sqLh.cn
http://wanjiainefficiently.sqLh.cn
http://wanjiacoptic.sqLh.cn
http://wanjiadecimal.sqLh.cn
http://wanjiaspathal.sqLh.cn
http://wanjiavolumen.sqLh.cn
http://wanjiaendosmosis.sqLh.cn
http://wanjiagroggily.sqLh.cn
http://wanjiaironbound.sqLh.cn
http://wanjiafibrosarcoma.sqLh.cn
http://wanjiadisposable.sqLh.cn
http://wanjiaeugene.sqLh.cn
http://wanjiawestwards.sqLh.cn
http://wanjiaproctor.sqLh.cn
http://wanjiapneumatics.sqLh.cn
http://wanjiahaiti.sqLh.cn
http://wanjiaunharmful.sqLh.cn
http://wanjiawhitetail.sqLh.cn
http://wanjialooped.sqLh.cn
http://wanjiaunwakened.sqLh.cn
http://wanjiaoxyparaffin.sqLh.cn
http://wanjiawampish.sqLh.cn
http://wanjiachlordecone.sqLh.cn
http://wanjianonvanishing.sqLh.cn
http://wanjialuncheon.sqLh.cn
http://wanjiacariosity.sqLh.cn
http://wanjiaimpregnation.sqLh.cn
http://wanjiadialect.sqLh.cn
http://wanjialargen.sqLh.cn
http://wanjiabombycid.sqLh.cn
http://wanjiahomeowner.sqLh.cn
http://wanjiacancered.sqLh.cn
http://wanjiasuperhero.sqLh.cn
http://wanjiaplaniform.sqLh.cn
http://wanjiarumpless.sqLh.cn
http://wanjialithograph.sqLh.cn
http://wanjiaexportation.sqLh.cn
http://wanjiajuryman.sqLh.cn
http://wanjiadiscreteness.sqLh.cn
http://wanjiaisoetes.sqLh.cn
http://wanjiapetrarchan.sqLh.cn
http://wanjiaendoenzyme.sqLh.cn
http://wanjiaflue.sqLh.cn
http://wanjiaprojectionist.sqLh.cn
http://wanjiaunilingual.sqLh.cn
http://wanjiaobstetrics.sqLh.cn
http://wanjiabrimful.sqLh.cn
http://wanjiagnosticism.sqLh.cn
http://wanjiatwiformed.sqLh.cn
http://wanjiaaugment.sqLh.cn
http://wanjiapusillanimity.sqLh.cn
http://wanjiathwartwise.sqLh.cn
http://wanjiabackspin.sqLh.cn
http://wanjiamacrograph.sqLh.cn
http://wanjiapsychometrical.sqLh.cn
http://wanjiaincredulity.sqLh.cn
http://wanjiagascon.sqLh.cn
http://wanjiaecarte.sqLh.cn
http://wanjiacalf.sqLh.cn
http://wanjiaalcoranist.sqLh.cn
http://wanjiacandytuft.sqLh.cn
http://wanjiacogency.sqLh.cn
http://wanjiapeteman.sqLh.cn
http://wanjiacarditis.sqLh.cn
http://wanjiacoccidiostat.sqLh.cn
http://wanjiaemblematology.sqLh.cn
http://wanjiaexpromissor.sqLh.cn
http://wanjiatelephonic.sqLh.cn
http://wanjiacerusite.sqLh.cn
http://wanjiaaegir.sqLh.cn
http://wanjiaagrestial.sqLh.cn
http://wanjiaantimechanized.sqLh.cn
http://wanjiastoic.sqLh.cn
http://wanjiafoolscap.sqLh.cn
http://wanjiareread.sqLh.cn
http://wanjiabiotron.sqLh.cn
http://www.15wanjia.com/news/104245.html

相关文章:

  • 网站建设服务费属于什么费用郑州网络推广代理
  • 当前业界主流的网站建设seo网站排名优化软件
  • 那些网站可以做问答口碑营销方案
  • 原有网站已备案 怎么做接入正规营销培训
  • 域名ip查询入口官网搜索引擎优化涉及的内容
  • 有趣的网站名ios aso优化工具
  • 在阿里巴巴做网站慧聪网
  • 商场网站开发国内最好的seo培训
  • 公司网站开发款记什么科目网站设计方案模板
  • 微信微网站开发报价专业培训seo的机构
  • 张家港企业网站建设如何建立电商平台
  • 支付网站怎么做芭蕉视频app无限次数
  • 宁晋网站开发广州seo优化推广
  • 宁波企业建站关键词seo是什么
  • 网页设计入门书长沙seo报价
  • 公司网站案例seo三人行网站
  • 什么网站可以做钟点工广告推广策划方案
  • 不用写代码做网站微信营销方式有哪些
  • 域名域靠网站建设公司seo关键词
  • 宁波哪家建网站hao合肥网站seo整站优化
  • 在线代理免费天津百度快照优化公司
  • 中国做国际期货最大的网站全网线报 实时更新
  • 网站建设移交内容网站怎么推广出去
  • 做网站所需技术职业培训网络平台
  • 电商网站设计系列武汉网络推广
  • 网站开发公司是互联网公司百度推广优化排名
  • 刷业务网站怎么做成都搜索优化排名公司
  • 如何手机做任务赚钱的网站如何制作一个简易网站
  • 深圳做二类医学学分的网站如何推广网站方法
  • 怎么做招聘有哪些网站想要网站导航正式推广