三元長(zhǎng)整數(shù)加減法源代碼_第1頁(yè)
三元長(zhǎng)整數(shù)加減法源代碼_第2頁(yè)
三元長(zhǎng)整數(shù)加減法源代碼_第3頁(yè)
三元長(zhǎng)整數(shù)加減法源代碼_第4頁(yè)
三元長(zhǎng)整數(shù)加減法源代碼_第5頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

#include<stdio.h>#include<stdlib.h>#include<malloc.h>#include<math.h>typedefstructnode{intdata;structnode*next;}node,*nodelist;structnode*initnode1()//初始化鏈表{structnode*head1;if((head1=(structnode*)malloc(sizeof(structnode)))==NULL)exit(-1);head1->next=NULL;returnhead1;}structnode*initnode2()//初始化鏈表{structnode*head2;if((head2=(structnode*)malloc(sizeof(structnode)))==NULL)exit(-1);head2->next=NULL;returnhead2;}structnode*createlist1(structnode*head1)//創(chuàng)建鏈表{char*pa[3];inti;chara[5]={0},b[5]={0},c[5]={0};intd;structnode*p=NULL,*p1=NULL,*L1=NULL;printf("請(qǐng)輸入第一個(gè)數(shù)的位數(shù)(小于12):");scanf("%d",&d);printf("請(qǐng)輸入第一個(gè)12位以內(nèi)的整數(shù)(從個(gè)位數(shù)起每四位用一個(gè)空格隔開(kāi)):");if((12-d)<4)scanf("%s%s%s",a,b,c);if((12-d)>=4&&(12-d)<8)scanf("%s%s",b,c);if((12-d)>=8&&(12-d)<12)scanf("%s",c);pa[0]=c;pa[1]=b;pa[2]=a;for(i=0;i<=2;i++){p=(structnode*)malloc(sizeof(structnode));(p->data)=atoi(pa[i]);//printf("%d",p->data);{head1->next=p;p1=p;}else{p1->next=p;p1=p;}}L1=head1;returnL1;}structnode*createlist2(structnode*head2)//創(chuàng)建鏈表{char*pa[3];inti;chara[5]={0},b[5]={0},c[5]={0};intd;printf("請(qǐng)輸入第二個(gè)數(shù)的位數(shù)(小于12):");scanf("%d",&d);printf("請(qǐng)輸入第二個(gè)12位以內(nèi)的整數(shù)(從個(gè)位數(shù)起每四位用一個(gè)空格隔開(kāi)):");if((12-d)<4)scanf("%s%s%s",a,b,c);if((12-d)>=4&&(12-d)<8)scanf("%s%s",b,c);if((12-d)>=8&&(12-d)<12)scanf("%s",c);pa[0]=c;pa[1]=b;pa[2]=a;for(i=0;i<=2;i++){p=(structnode*)malloc(sizeof(structnode));(p->data)=atoi(pa[i]);//printf("%d",p->data);if(head2->next==NULL){head2->next=p;p1=p;}else{p1->next=p;p1=p;}}L2=head2;returnL2;}voidminus(structnode*p1,structnode*p2){inta[3],i;p1=p1->next;p2=p2->next;for(i=0;i<=1;i++){if((p1->data)-(p2->data)<0){p1->next->data=p1->next->data-1;a[i]=p1->data+10000-p2->data;p1=p1->next;p2=p2->next;}else{a[i]=p1->data-p2->data;p1=p1->next;p2=p2->next;}}a[2]=p1->data-p2->data;printf("結(jié)果為:");for(i=2;i>=0;i--){printf("%d",a[i]);}printf("\n");}intadd(structnode*p1,structnode*p2){intm1,m2,a[2],p[3]; p1=p1->next;p2=p2->next;p[0]=p1->data+p2->data; a[0]=p[0]/10000; p[0]=p[0]%10000; p[1]=p1->next->data+p2->next->data+a[0]; a[1]=p[1]/10000; p[1]=p[1]%10000; p[2]=p1->next->next->data+p2->next->next->data+a[1]; if(abs(p[2])>=10000)return-1;//gaile if(p[2]!=0) printf("%d,%d,%d",p[2],p[1],p[0]); if(p[2]==0&&p[1]!=0) printf("%d,%d",p[1],p[0]); if(p[2]==0&&p[1]==0) printf("%d",p[0]); return0;}intmain(){inta;structnode*head1,*head2,*p1,*p2;head1=initnode1();head2=initnode2();printf("請(qǐng)輸入您需要的功能:\n");printf("1.加法運(yùn)算\n");printf("2.減法運(yùn)算\n");printf("0.退出\n");scanf("%d",&a);while(a!=0){switch(a){case1:{p1=createlist1(head1);p2=createlist2(head2);add(p1,p2);}break;case2:{p1=createlist1(head1);p2=createlist2(head2);minus(p1,p2);}break;

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論