全文预览

西南交大C 实验七

上传者:苏堤漫步 |  格式:doc  |  页数:11 |  大小:43KB

文档介绍
blepower(inta,intb){intmul=1,i;?for(i=0;i<b;i++) mul=mul*a;?returnmul;}?4.#include<iostream>usingnamespacestd;voidmain(){ cout<<"学号:"<<endl;?cout<<"========================================="<<endl;?intx,y,z,gy,gb;?intmax(intm,intn);?intmin(intm,intn);?cout<<"请输入2个正整数:";?cin>>x>>y;?if(x<y)?{?z=x; x=y; y=z;}?gy=max(x,y);?gb=min(x,y);?cout<<"最大公约数是:"<<gy<<endl;?cout<<"最小公倍数是:"<<gb<<endl;}intmax(intm,intn){?intt;?t=m%n;?while(t!=0)?{ m=n; n=t; t=m%n;?}?returnn;}intmin(intm,intn){?intmax(int,int);?return(m*n)/max(m,n);}5.#include<iostream>usingnamespacestd;voidmain(){ cout<<"学号:"<<endl;?cout<<"========================================="<<endl;?intm,n,i,j,sum;?sum=0;?boolfact(inti);?cout<<"请输入2个正整数m,n:";?cin>>m>>n;?for(i=m;i<=n;i++)if(fact(i))?sum=sum+i;?cout<<m<<"~"<<n<<"之间所有完数之和为:"<<sum<<endl;}

收藏

分享

举报
下载此文档