资源描述:
《大数据结构课程设计-大数问题》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、标准文案大数运算问题的程序设计例如:输入第一个数为:1234567890987654321,输入第二个数为:1239874355878921367863则输出结果:1234567890987654321*1239874355878921367863=正确答案。源程序:#include"stdio.h"#include"malloc.h"#include"string.h"#defineMAX20typedefcharDataType;typedefstruct{DataTypedata[MAX];i
2、nttop;}SeqStack,*PSeqStack;intStackEmpty(PSeqStackS){returnS->top==-1;}intStackFull(PSeqStackS){returnS->top==MAX-1;大全标准文案}voidPush(PSeqStackS,DataTypex){if(StackFull(S))printf("栈中元素已经满了!请先出栈或把栈置空!");S->data[++S->top]=x;}DataTypePop(PSeqStackS){if(St
3、ackEmpty(S))printf("栈为空,无法出栈,请检查a!");returnS->data[S->top--];}DataTypeStackTop(PSeqStackS){if(StackEmpty(S))printf("栈为空,无法出栈,请检查!");returnS->data[S->top];}voidAdd(PSeqStackM,PSeqStackN,PSeqStackaddnumber)//加法函数{大全标准文案intzongshu,shiweishu=0;if(M->to
4、p==N->top){while(M->top!=-1){zongshu=Pop(M)-48+Pop(N)-48+shiweishu;shiweishu=zongshu/10;Push(addnumber,(zongshu%10+48));}}elseif(M->top>N->top){while(N->top!=-1){zongshu=Pop(M)-48+Pop(N)-48+shiweishu;shiweishu=zongshu/10;Push(addnumber,(zongshu%10+48))
5、;}while(M->top!=-1){zongshu=Pop(M)-48+shiweishu;shiweishu=zongshu/10;大全标准文案Push(addnumber,(zongshu%10+48));}}elseif(M->toptop){while(M->top!=-1){zongshu=Pop(M)-48+Pop(N)-48+shiweishu;shiweishu=zongshu/10;Push(addnumber,(zongshu%10+48));}while(N->to
6、p!=-1){zongshu=Pop(N)-48+shiweishu;shiweishu=zongshu/10;Push(addnumber,(zongshu%10+48));}}}intMinus(PSeqStackM,PSeqStackN,PSeqStackaddnumber)大全标准文案//减法函数{intj=0;intkk;if(M->top==N->top){for(j=0;j<=M->top;j++){if(M->data[j]>N->data[j]){while(N->top!=-1)
7、{if(Pop(M)>=Pop(N)){kk=(Pop(M)-48)-(Pop(N)-48);Push(addnumber,(kk+48));}else{Push(addnumber,((Pop(M)-48)+10-(Pop(N)-48)+48));Push(M,(Pop(M)-1));}大全标准文案}j=N->top+1;}elseif(M->data[j]data[j]){printf("被减数比减数小!请检查a!");j=N->top+1;}}Push(addnumber,0);r
8、eturn1;}elseif(M->top>N->top){while(N->top!=-1){if(Pop(N)<=Pop(M)){kk=(Pop(M)-48)-(Pop(N)-48);Push(addnumber,(kk+48));}else大全标准文案{Push(addnumber,(Pop(M)-48+10-(Pop(N)-48)+48));//先要把字符转成数字,相减后再把数字转成字符Push(M,(Pop(M)-1));}}while(M->top!=-1