大数问题Word格式文档下载.docx

上传人:b****2 文档编号:15287771 上传时间:2022-10-29 格式:DOCX 页数:9 大小:15.88KB
下载 相关 举报
大数问题Word格式文档下载.docx_第1页
第1页 / 共9页
大数问题Word格式文档下载.docx_第2页
第2页 / 共9页
大数问题Word格式文档下载.docx_第3页
第3页 / 共9页
大数问题Word格式文档下载.docx_第4页
第4页 / 共9页
大数问题Word格式文档下载.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

大数问题Word格式文档下载.docx

《大数问题Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《大数问题Word格式文档下载.docx(9页珍藏版)》请在冰豆网上搜索。

大数问题Word格式文档下载.docx

len=strlen(s);

if(s[0]=='

-'

flag=1;

for(i=len-flag;

i>

=1;

i--)

if((s[len-i]-'

0'

)<

0||(s[len-i]-'

)>

9)

printf("

\t\t\t你输入的第%d位不合法,按任意键重新输!

!

"

len-i+1);

//对于非数字的检测

getch();

gotorestart;

}

else

a[i]=s[len-i]-'

;

if(flag)

a[0]=-(len-1);

//数字串首位的一个正负表示及串的长度

a[0]=len;

break;

return;

voidmy_print(int*a)

inti;

if(a[0]<

0)printf("

-"

);

if(a[0]==0)

0"

for(i=abs(a[0]);

%d"

a[i]);

\n"

voidformat(int*a)

intp;

for(p=1;

p<

a[0]||a[p]>

=10;

p++)

if(p>

=a[0])a[p+1]=0;

a[p+1]+=a[p]/10;

a[p]=a[p]%10;

=a[0])a[0]=p;

}

voidadd(int*a,int*b,int*c)

intlen,i;

b[0])

len=a[0];

len=b[0];

for(i=1;

i<

=len;

i++)

c[i]=a[i]+b[i];

if(len<

a[0])

for(;

=a[0];

c[i]=a[i];

c[0]=a[0];

for(;

=b[0];

c[i]=b[i];

c[0]=b[0];

format(c);

voidcommaltiply(int*a,intx,int*b)

b[i]=a[i]*x;

b[0]=a[0];

format(b);

voidmatiply(int*a,int*b,int*c)

inti,temp[MAX],j;

commaltiply(a,b[1],c);

for(i=2;

if(b[i]==0)

c[0]++;

for(j=c[0];

j>

1;

j--)

c[1]=0;

commaltiply(a,b[i],temp);

for(j=1;

j<

i;

j++)

commaltiply(temp,10,temp);

add(c,temp,c);

voiddectobin(int*a,int*b)//十进制转换成二进制

b[0]=0;

while(a[0]>

0)

b[0]++;

b[b[0]]=a[1]%2;

p=a[0];

while(p>

if(a[p]%2&

&

p>

1)

a[p-1]+=10;

a[p]/=2;

if(a[a[0]]==0)

a[0]--;

p--;

voidformat1(int*a)

for(i=1;

if(a[i]<

a[i]+=10;

a[i+1]-=1;

voidsub_1(int*a,int*b,int*c)

c[i]=a[i]-b[i];

if(a[0]==b[0])

gotoloop;

loop:

format1(c);

i=c[0];

if(c[i]==0)

i--;

c[0]=i;

voidsub(int*a,int*b,int*c)

inti,flag=0;

if(a[i]!

=b[i])

{

if(flag==0)

c[0]=0;

flag=0;

i=a[0];

while(i>

if(a[i]>

b[i])

sub_1(a,b,c);

sub_1(b,a,c);

if(a[0]>

elseif(a[0]<

c[0]=-c[0];

c[0]=c[0];

/**********************************/

intmain()

inti,a[MAX],b[MAX],c[MAX];

charyn;

strat:

system("

cls"

\n\n\n"

\t\t\t**************************************\n"

\t\t\t**\n"

\t\t\t*1.大整数的加法*\n"

\t\t\t*2.大整数的减法*\n"

\t\t\t*3.大整数的乘法*\n"

\t\t\t*4.大整数进制转换*\n"

\t\t\t*5.帮助?

*\n"

\t\t\t*6.退出*\n"

\n\n\t\t\t请选择(1-6):

yn=getch();

if(yn=='

1'

||yn=='

2'

3'

4'

5'

6'

\n\t\t\t输入不合法!

按任意键重新输入!

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销 > 公共行政管理

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1