资源简介
c语言写的大数计算器,可用于计算10^100数量级的数据,可用于计算加法,乘法,幂次等,主要是算法的实现思路。
代码片段和文件信息
/* Extended precision integer calculator
* Implements + * and ^ (power of) operations
*
* Skeleton code written by Jianzhong Qi March 2018
*
*/
#include
#include
#include
#include
#define INT_SIZE 100 /* max number of digits per integer value */
#define LINE_LEN 103 /* maximum length of any input line */
#define NUM_VARS 10 /* number of different huge int “variables“ */
#define ASN_OP ‘=‘ /* assignment operator */
#define ECH_OP ‘?‘ /* echo operator */
#define ADD_OP ‘+‘ /* addition operator */
#define MUL_OP ‘*‘ /* multiplication operator */
#define POW_OP ‘^‘ /* power of operator */
#define OPR1_POS 1 /* position of the first operand */
#define OPR2_POS 3 /* position of the second operand */
#define OP_POS 2 /* position of the operator */
#define CH_ZERO ‘0‘ /* character 0 */
#define EXIT_CMD “exit“ /* command to exit */
#define PROMPT “> “ /* command prompt */
#define CMT_FLAG ‘%‘ /* indicator for comment line */
typedef int digit_t; /* a decimal digit */
typedef digit_t huge_t[INT_SIZE]; /* one huge int “variable“ */
/* add your constant and type definitions here */
/****************************************************************/
/* function prototypes */
void read_line(char *line int max_len);
void init(huge_t vars[] int lens[]);
void echo(huge_t vars[] int lens[] int opr1_index);
void assign(huge_t vars[] int lens[] int opr1_index char *opr2_str);
void add(huge_t vars[] int lens[] int opr1_index char *opr2_str);
void multiply(huge_t vars[] int lens[] int opr1_index char *opr2_str);
void power(huge_t vars[] int lens[] int opr1_index char *opr2_str);
/* add your function prototypes here */
/****************************************************************/
/* main function controls all the action do NOT modify this function */
int
main(int argc char *argv[]) {
char line[LINE_LEN+1]; /* to hold the input line */
huge_t vars[NUM_VARS]; /* to hold 10 huge integers */
int lens[NUM_VARS]; /* to hold the length of the 10 vars */
int opr1_index; /* index of the first operand in command */
char op; /* operator in command */
init(vars lens);
while (1) {
printf(PROMPT); /* print prompt */
read_line(line LINE_LEN); /* read one line of command */
if (line[0] == CMT_FLAG) { /* print comment in the test data */
printf(“%s\n“ line); /* used to simplify marking */
continue;
}
if (strcmp(line EXIT_CMD) == 0) { /* see if command is “exit“ */
return 0;
}
opr1_index = line[OPR1_POS] - CH_ZERO;/* first var number at line[1] */
op = line[OP_POS]; /* operator at line[2] */
if (op == ECH_OP) { /* print out the variable */
echo(vars lens opr1_index);
continue;
}
/* do the calculation second operand starts at line[3] */
if (op == ASN_OP) {
assign(vars lens opr1_index line+OPR2_POS);
} else i属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 8142 2018-04-16 22:13 calc.c
文件 37446 2018-04-16 22:13 calc.exe
文件 8924 2018-04-16 22:13 calc.o
文件 2639 2018-04-16 22:10 测试结果(1).jpg
文件 13504 2018-04-16 22:10 测试结果.jpg
- 上一篇:人事管理系统C语言课程设计报告
- 下一篇:基于c++的格斗游戏
相关资源
- CCS FFT c语言算法
- 小波变换算法 c语言版
- 3des加密算法C语言实现
- DES加密算法C语言实现
- 线性回归算法c语言实现
- 基于C语言的模拟退火算法
- C语言实现的DES对称加密算法
- 用VC6.0实现多边形扫描线填充算法
- c语言编写的货郎担算法
- Em算法(使用C++编写)
- STM32烧写算法flash包
- 永磁同步电机的FOC控制算法
- Proteus仿真:PID算法输出.rar
- 一个模糊PID温度控制算法源代码
- 经典滤波算法
- KMP算法C语言程序
- SVM算法实现(源码+文档)
- 算法A律U律实现
- 人工蜂群算法.docx
- BlowFish加密算法
- C语言常用算法源代码
- c++数组快排算法
- 算法表达式求值.cpp
- PID算法.c
- QR二维码C++源码 算法实现
- 基于opencv漫水填充算法综合
- 信息学奥赛一本通——算法部分
- 银行家算法分配资源的模拟实现(m
- C语言程序设计50例.docx
- 常见排序算法比较.cpp
川公网安备 51152502000135号
评论
共有 条评论