欢迎来到天天文库
浏览记录
ID:44509462
大小:223.00 KB
页数:4页
时间:2019-10-22
《数据结构与算法作业第三章》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、3.12源代码:#includc#includc#includeusingnamespacestd;stringreverse(strings){stringreverse=“";for(inti=0;i2、g_byte;aim=aim/ns;Jwhilc(aim!=0);result=reverse(result);returnresult;}intmainO{intm,n;cout<<"Inputnumberyouwanttoconverttheinputintothesystem:cin»m;cout<<"Inputthenumberyouwanttoconvert:“;cin»n;cout<<"Theresultis"«trans(n,m)«endl;system(/zpausez,);return0;}程序运行截图:3.16源代码:(1)inta3、km(intm,intn){if(m==0)returnn+1;elseif(n二二0)returnakm(m-1,1);elsereturnakm(m-l,akm(m,nT));}(2)intakm(intm,intn){inttemp;if(m==0)returnn+1;if(n==0)returnakm(m-1,1):temp=akm(m,nT);returnakm(m-1,temp);}程序运行结果:3.21源代码:#includeusingnamespacestd;intGCD(intm,intn){if(n=0)ret4、urnm;elsereturnGCD(n,m%n);}voidmain(){jntnuml,num2;cout«"InputtwonumbersforGCD:〃«endl;cin»numl»num2;cout«"Thelargestcommonfactorof"«numl«"and"<
2、g_byte;aim=aim/ns;Jwhilc(aim!=0);result=reverse(result);returnresult;}intmainO{intm,n;cout<<"Inputnumberyouwanttoconverttheinputintothesystem:cin»m;cout<<"Inputthenumberyouwanttoconvert:“;cin»n;cout<<"Theresultis"«trans(n,m)«endl;system(/zpausez,);return0;}程序运行截图:3.16源代码:(1)inta
3、km(intm,intn){if(m==0)returnn+1;elseif(n二二0)returnakm(m-1,1);elsereturnakm(m-l,akm(m,nT));}(2)intakm(intm,intn){inttemp;if(m==0)returnn+1;if(n==0)returnakm(m-1,1):temp=akm(m,nT);returnakm(m-1,temp);}程序运行结果:3.21源代码:#includeusingnamespacestd;intGCD(intm,intn){if(n=0)ret
4、urnm;elsereturnGCD(n,m%n);}voidmain(){jntnuml,num2;cout«"InputtwonumbersforGCD:〃«endl;cin»numl»num2;cout«"Thelargestcommonfactorof"«numl«"and"<
此文档下载收益归作者所有