c语言大整数运算问题高分求助各位帮忙,不胜感激 写了一个利用循环链表进行超大整数四则运算的c程序

加减法运算没有问题,只是乘法运算时,对于某些数字即使是大整数也可以运算且输出正确结果,但对某些即使小数字运算时却出现内存错误的提示。求高手看下乘法函数哪里有问题,不胜感激... 加减法运算没有问题,只是乘法运算时,对于某些数字即使是大整数也可以运算且输出正确结果,但对某些即使小数字运算时却出现内存错误的提示。求高手看下乘法函数哪里有问题,不胜感激。程序太长,只贴出了乘法函数,另外打印函数和main函数会在后面补充,求教,非常感谢。
#include<stdio.h>

#include<stdlib.h>
#define HUNTHOU 10000
typedefstruct node
{
int data;
struct node *next;
}NODE; /*定义链表结构*/
/*输入超长整数,存入链表*/
NODE *inputint(void)
{
NODE *s,*ps,*qs;
struct number
{
int num;
struct number *np;
}*p,*q;
int i,k;
long sum;
char c;
p=NULL; /*指向输入的整数,链首为长整数的最低位,链尾为长整数的最高位*/
while((c=getchar())!='\n'){ /*输入整数,按字符接收数字*/
if(c>='0'&&c<='9'){ /*若为数字则存入*/
q=(struct number *)malloc(sizeof(struct number)); /*申请空间*/
q->num=c-'0'; /*存入一位整数*/
q->np=p; /*建立指针*/
p=q;
}
}
s=(NODE*)malloc(sizeof(NODE));
s->data=-1; /*建立表求超长整数的链头*/
ps=s;
while(p!=NULL){ /*将接收的临时数据链中的数据换为所要求的标准形式*/
while(i<4&&p!=NULL){ /*取出低四位*/
sum=sum+k*(p->num);
i++;
p=p->np;
k=k*10;
}
qs=(NODE
*)malloc(sizeof(NODE)); /*申请空间*/
qs->data=sum; /*赋值,建立链表*/
ps->next=qs;
ps=qs;
}
ps->next=s; /*指向头结点*/
return s;
}
/*在u结点插入一个新的NODE,其值为num*/
NODE *insert_after(NODE *u,int num)
{
NODE *v;
v=(NODE*)malloc(sizeof(NODE)); /*申请一个NODE*/
v->data=num; /*赋值*/
u->next=v; /*在u结点后插入一个NODE*/
return v;
}
/*求两个大整数的乘积,并返回指向|(*p)*(*q)|结果的指针*/
NODE *mulint(NODE *p,NODE *q)
{
NODE *pc,*qc,*s,*t;
int
i,number,total;
s=(NODE
*)malloc(sizeof(NODE)); /*建立存放乘积的链表表头*/
s->data=-1; /*给存放乘积的链表表头赋值-1*/
pc=p->next;
t=s;i=0; /* i为进位 */
while(pc->data!=-1){ /*不是表头*/
qc=q->next;
while(qc->data!=-1){ /*不是表头*/
if(t->next==NULL){
total=pc->data*qc->data+i; /*对应位的积与前次进位的和*/
i=total/HUNTHOU; /*求进位*/
number=total-i*HUNTHOU; /*求出需要存入链表链表中的部分的数值*/
t=insert_after(t,number); /*将部分积存入s指向的链表中*/
}
else{
total=total+pc->data*qc->data+i;
i=total/HUNTHOU;
number=total-i*HUNTHOU;
t=insert_after(t,number);
}
qc=qc->next; /*移动指针*/
}
if(i!=0){
t=insert_after(t,i); /*处理最后一次进位*/
t->next=s; /*指向头结点*/
}
pc=pc->next; /*移动指针*/
}
return s; /*返回指向积的结构指针*/
}
void printint(NODE *s)
{
if(s->next->data!=-1) /*若不是表头,则输出*/
{
printint(s->next); /*递归输出*/
if(s->next->next->data==-1)
printf("%d",s->next->data); /*打印最高位*/
else{
int i,k=10000;
for(i=1;i<=4;i++,k/=10) /*按字符输出不足4位补0 */
putchar('0'+s->next->data %(k)/(k/10) );
}
}
}
int main(void)
{
NODE *s1,*s2,*s;
char c;
NODE *inputint(),*insert_after(),*mulint();
do{
printf("Enter s1=");
s1=inputint(); /*输入大整数,存入链表*/
printf("Enter s2=");
s2=inputint();
s=mulint(s1,s2); /*求积*/
printint(s); /*输出结果*/
putchar('\n');
}while(c=getchar()=='\n');
return0;
}

不好意思,c程序粘贴时漏掉一行代码
在建立链表NODE *inputint(void)函数里,第一个while循环while(p!=NULL){

后面jia加上 sum=0,i=0,k=1
不好意思,没有人给看下么
展开
 我来答
wssznh1999
2012-07-22 · TA获得超过428个赞
知道小有建树答主
回答量:232
采纳率:0%
帮助的人:362万
展开全部
NODE *mulint(NODE *p,NODE *q)
{
NODE *pc,*qc,*s,*t,*r;
int i,number,total = 0;
s=(NODE
*)malloc(sizeof(NODE)); /*建立存放乘积的链表表头*/
s->data=-1; /*给存放乘积的链表表头赋值-1*/
pc=p->next;
r=t=s;
t->next = s;
i=0; /* i为进位 */
while(pc->data!=-1){ /*不是表头*/
qc=q->next;
while(qc->data!=-1){ /*不是表头*/
if(t->next->data==-1){
total=pc->data*qc->data+i; /*对应位的积与前次进位的和*/
i=total/HUNTHOU; /*求进位*/
number=total-i*HUNTHOU; /*求出需要存入链表链表中的部分的数值*/
t=insert_after(t,number); /*将部分积存入s指向的链表中*/
t->next=s;
}
else{
total=t->next->data+pc->data*qc->data+i;
i=total/HUNTHOU;
number=total-i*HUNTHOU;
t->next->data=number;
t=t->next;
}
total = 0;
qc=qc->next; /*移动指针*/
}
if(i!=0){
t=insert_after(t,i); /*处理最后一次进位*/
t->next=s; /*指向头结点*/
}
i = 0;
pc=pc->next; /*移动指针*/
t=r->next;
r=r->next;
}
return s; /*返回指向积的结构指针*/
}
追问
谢谢你,那边答案先看了,按你说的改了一句就弄好了。这两边分都给你吧。但是我分不多了,这个程序其实还要算除法,然后利用乘法算100的阶乘,最后还要求16位的数中最小的素数和最大的素数,非常麻烦。所以再有问题时能不能再请教你,可能分不会给太多了,课题期限都过了,很感激你。
densmdnes
2012-07-21
知道答主
回答量:4
采纳率:0%
帮助的人:6190
展开全部
Were you aware your personal computer studies and in addition appear every single movements as well as amount of info obtained.And in addition any man or woman who receives using of your own appliance can view the routines,Windows 7 Ultimate Product Key,including . bit-torrent traditions,converse document,pictures,audio tracks,and also movie papers.At this stage somebody begin to see the massive graphic along with eliminating in addition to getting rid of data merely reomes an extremely small percentage in the paperwork.Allowing you prone to promoting of this secret specifics.
That is you'll want the assistance of ParetoLogic Private privateness Options which is enhanced to obtain each of the information identified merely by normal ideas for example bit-torrent,limewire plus reside.
This technique is not hard to do,along with for good takes away the majority of files related to your online task just like good websites gone to,Windows 7 Keygen, following fast foods,Office 2010 Product Key, additionally private particulars which include consideration information, ID's, in addition to standard bank as well as credit card data.Also the secured removal function complies together with as well as far outshines the Ough.Ersus. Regulators Affiliate marketer firms Features as well as aids House windows 2000, Windows 7, along with Goblet glass windows Panorama customers.So that you can keep up-to-date with all the current styles during software methods the product as well as program or maybe service is up-to-date usually seize records by using clean offered applications.To find precisely what the notebook continues to be keeping away from simply clicking for almost any no cost check out

Preserving glass windows feline cost-free and risk-free??
??
Typically??
??
Will you be considering boosting system together with the latest glass windows A??
??
Mysql database database database so that you can MSSQL shredding sources software program is a perfe??
??
Do not get me wrong: I do believe G-mail stones??
??
The Sony VAIO VPCSE1AFX is built to cater to the n
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式