大数运算
											要求输入两个相对较大的十进制整数,完成加减乘除四则运算要求:
1. 输入的整数位数不低于10位;
2. 输入的整数可正可负;
3. 能通过菜单运行程序。
不会啊,求解,要用大数运算,完全没思路
	    2017-05-24 15:38
  
	    2017-05-24 16:36
  
	    2017-05-24 16:36
  [此贴子已经被作者于2017-5-24 16:41编辑过]

	    2017-05-24 16:38
  
	    2017-05-24 16:50
  
	    2017-05-24 17:28
  
程序代码:#include"Big_Intger.h"
#include<windows.h>
#define BUFF_MAX      10              //最大缓冲区
void Init_Data(char** );              //初始化数据
int main()
{
    char* p1=NULL;
    char* p2=NULL;
    char* p3=NULL;
    puts("请输入被除数:");
    Init_Data(&p1);
    puts("请输入除数:");
    Init_Data(&p2);
    p3=Big_Intger_Div(p1,p2);
    puts("结果是:");
    puts(p3);
    free(p1);
    free(p2);
    free(p3);
    system("pause");
    return 0;
}
void Init_Data(char** p)                //初始化数据
{
    char* pt=NULL;
    int length=0;
    pt=*p=(char* )malloc((BUFF_MAX)*sizeof(char));
    assert(*p!=NULL);
    memset(*p,0,sizeof(pt));
    while (isdigit(*pt=getchar()))
    {
        ++length;
        if (length%(BUFF_MAX-1)==0)
        {
            assert(realloc(*p,(length+BUFF_MAX)*sizeof(char)));
            memset(*p+length,0,BUFF_MAX*sizeof(char));
            pt=*p+length-1;
        }
        ++pt;
    }
    if (*pt=='\n')
    {
        *pt='\0';
        return ;
    }
       puts("输入数据有误!");
       exit(0);
}
程序代码:#ifndef  _BIG_INGETER_MATH_
#define _BIG_INGETER_MATH_
#include"List.h"
#include<ctype.h>
typedef char Big_Intger_Data;
Big_Intger_Data* Big_Intger_Div(Big_Intger_Data* ,Big_Intger_Data* );               //初始化   
        
void Big_Intger_Input(PList ,Big_Intger_Data* );             //输入数据
void Big_Intger_Fun(PList* p,Big_Intger_Data* s);  //执行主体
void Big_Intger_Get_DataInbuff(PList* p);         //读取数据到缓冲区
int Big_Intger_Comp_Data(PList ,PList );          //比较大小
void Big_Intger_Sub_Data(PList ,PList);           //作减法
Big_Intger_Data* Big_Intger_Div(Big_Intger_Data* ch1,Big_Intger_Data* ch2)           //初始化 
{
    PList p[3]={0};     //p[0]-被除数-p[1]-除数-p[2]-除数缓冲区
    Big_Intger_Data* s=NULL;
    Creat_Link(&p[0],NULL,sizeof(Big_Intger_Data));
    Creat_Link(&p[1],NULL,sizeof(Big_Intger_Data));
    Creat_Link(&p[2],NULL,sizeof(Big_Intger_Data));
    Big_Intger_Input(p[0],ch1);
    Big_Intger_Input(p[1],ch2);
    s=(Big_Intger_Data*)malloc((p[0]->length-p[1]->length+2)*sizeof(Big_Intger_Data));
    if (*(Big_Intger_Data*)(p[1]->front->next->Element)==0)
        return strdup("除数不能为0!");
    if (Big_Intger_Comp_Data(p[0],p[1])<0)
        return strdup("0");
    assert(s);
    memset(s,0,(p[0]->length-p[1]->length+2)*sizeof(Big_Intger_Data));
    Big_Intger_Fun(p,s);
    Del_List(&p[0],1);
    Del_List(&p[1],1);
    Del_List(&p[2],1);
    return s;
}
void Big_Intger_Input(PList p,Big_Intger_Data* ch)    //把数据写入链表
{
    while (*ch!='\0')
    {
        *ch-='0';
        Insert_Rear(p,ch++);
    }
}
void Big_Intger_Fun(PList* p,Big_Intger_Data* s)
{
    Big_Intger_Data d=0;
    int i=0;
    Big_Intger_Get_DataInbuff(p);
    while (1)
    {
        Big_Intger_Data ch=0;
        for (d=0;Big_Intger_Comp_Data(p[2],p[1])>=0;++d)
            Big_Intger_Sub_Data(p[2],p[1]);
        s[i++]=d+'0';
        if (p[0]->length==0)
            break;
        Get_Data_By_Front(p[0],&ch);
        Insert_Rear(p[2],&ch);
        Del_Front(p[0],NULL);
    }
}
void Big_Intger_Get_DataInbuff(PList* p)
{
    Big_Intger_Data ch=0;
    do
    {
       Get_Data_By_Front(p[0],&ch);
       Del_Front(p[0],NULL);
       Insert_Rear(p[2],&ch);
    }while (p[0]->length!=0&&Big_Intger_Comp_Data(p[2],p[1])<0);
}
int Big_Intger_Comp_Data(PList p1,PList p2)
{
    PListNode pt1=NULL;
    PListNode pt2=NULL;
    Big_Intger_Data a=0;
    Big_Intger_Data b=0;
    if (p1==NULL||p2==NULL)
        return -2;
    if (p1->length>p2->length)
        return 1;
    else if (p1->length<p2->length)
        return -1;
    pt1=p1->front->next;
    pt2=p2->front->next;
    if (*(Big_Intger_Data* )(pt1->Element)==0)
    {
        while (p1->length!=0&&*(Big_Intger_Data*)p1->front->next->Element==0)  //去0
            Del_Front(p1,NULL);
        return -1;
    }
    while (pt1!=p1->rear&&pt2!=p2->rear)
    {
         a=*(Big_Intger_Data* )(pt1->Element);
         b=*(Big_Intger_Data* )(pt2->Element);
        if (a>b)
            return 1;
        if (a<b)
            return -1;
        pt1=pt1->next;
        pt2=pt2->next;
    }
    return 0;
}
void Big_Intger_Sub_Data(PList p1,PList p2)  //大数减法
{
    PListNode pt1=NULL;
    PListNode pt2=NULL;
    Big_Intger_Data flag=0;
    if (p1==NULL||p2==NULL)
        return ;
    pt1=p1->rear->prior;
    pt2=p2->rear->prior;
    while (pt2!=p2->front)
    {
        Big_Intger_Data* a=(Big_Intger_Data* )pt1->Element;
        Big_Intger_Data* b=(Big_Intger_Data* )pt2->Element;
        if (*a<*b+flag)
        {
            *a+=10-*b-flag;
            flag=1;
        }
        else
        {
            *a-=*b+flag;
            flag=0;
        }
        pt1=pt1->prior;
        pt2=pt2->prior;
    }
    if (flag==0)
    {
        while (p1->length!=0&&*(Big_Intger_Data*)p1->front->next->Element==0)  //去0
            Del_Front(p1,NULL);
        return ;
    }
    while (pt1!=p1->front)  //剩余位数进行判断
    {
        Big_Intger_Data* a=(Big_Intger_Data*)pt1->Element;
        if (*a!=0)
        {
            *a-=1;
            break;
        }
        *a=9;
        pt1=pt1->prior;
    }
    while (p1->length!=0&&*(Big_Intger_Data*)p1->front->next->Element==0)  //去0
        Del_Front(p1,NULL);
}
#endif
[此贴子已经被作者于2017-5-28 21:46编辑过]

	    2017-05-25 13:11
  
	    2017-05-25 13:12
  
那个大位数把每一个输入数据储存在链表~结果保留在堆里面~在这里int 的大小已经对数据没啥影响了~~~~~~~										
					
	
	    2017-05-25 13:16
  
										
					
	
	    2017-05-25 17:23