C language with linked list for extra-long integer addition and subtraction (doing)

Source: Internet
Author: User

1#include <stdio.h>2#include <stdlib.h>3#include <math.h>4 structDulnode5 {6     intdata;7     structDulnode *next,*prev;8 };9typedefstructDulnode Dulnode;Tentypedef Dulnode *dulinklist; One intMain () A { - dulnode fuc_creat (Dulnode NUM); -     intfuc_print (Dulnode NUM); the     intFuc_compe (Dulnode num1,dulnode NUM2); -     intfuc_plus (Dulnode num1,dulnode NUM2); -     intfuc_sub (Dulnode num1,dulnode NUM2); -Dulnode Num1={num1.data=0}; +num1=fuc_creat (NUM1); - Fuc_print (NUM1); +     return 1; A } at dulnode fuc_creat (dulnode NUM) - { - dulinklist p,q; -     intI=0, block=0, j=1; -     inttemp[ -]; -     Charstr[101]; in gets (str); -q=&NUM; to      for(i=0;i< -&&str[i]!=' /'; i++) +     { -         if(str[i]<'0'|| Str[i]>'9') printf ("Input Error"); thetemp[i]=str[i]-'0'; * //printf ("Test_1%d\n", Temp[i]); $     }Panax Notoginseng      for(i=i-1; i>-1; i--) -     { theq->data=q->data+j*Temp[i]; +block++; Aj=j*Ten; the         if(block%4==0) +         { -p= (Dulnode *) malloc (sizeof(Dulnode)); $P->data=0; $p->next=Q; -p->prev=&NUM; -q->prev=p; thenum.next=p; -q=p;Wuyij=1; the         } - //printf ("test_2%d\n", q->data); Wu     } -     returnNUM; About } $ intfuc_print (Dulnode NUM) - { -printf"test_1 print\n"); - dulinklist Q; Aq=Num.next; +      Do the     { -printf"%d",q->data); $Q=q->Next; the} while(q==&NUM); theprintf"test_2 print\n"); the     return 1; the}

Vim+gcc+gdb Dafa is good, programming in Linux is wonderful.

Interstitial connection: Vim command +gdb command Http://pan.baidu.com/s/1pJKChHT file from Baidu Library, you can find it by yourself

1: Learn to Debug. Since learning this trick, no longer in the program of the printf (test ") code!

2:malloc function header file <stdlib.h> use p= (int */* to return the type, cast to p*/) malloc (n/* assigns several */*sizeof (int/* assigned to P's length */)). The space created by malloc will point P to the newly opened address, thereby losing the original point and, if necessary, reserving P's information in advance. Code 44 lines

3: The function type definition is defined as type int, then the value of the function return is that type. Code 23 is defined, code 55 returns, and code 19 receives the return value.

4: The struct pointer points to the structure body data q->data (*Q). It recommends the previous notation.

5: struct assigns initial value can write constructor (c + +? ) or assign a value directly at the time of definition, and concatenate the struct Delnode num1={num1.data=0} code 18 lines with commas between each element

6: Software engineering thinking needs to think ahead of the general how to write a good, what function to achieve what function. It is more necessary to likes our weak chickens. It is recommended that you write the main function first so that you can debug with less effort.

C language with linked list for extra-long integer addition and subtraction (doing)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.