欢迎来到天天文库
浏览记录
ID:55631055
大小:47.50 KB
页数:14页
时间:2020-05-21
《C++作业题及答案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、一、分析程序,写输出结果1.#include#includevoidmain(){intm,k,i;for(m=1;m<=10;m+=2){k=m/3;for(i=2;i<=k;i++)if(m%i)cout<voidfun();voidmain(){inti;for(i=1;i<5;i++)fun();cout<2、#includeintfun(intn){if(n==0)return1;return2*fun(n-1);}voidmain(){inta=5;cout<voidmain(){char*cp="word";for(inti=0;i<4;i++)cout<voidmain(){i3、ntmax;inta[10]={76,55,95,87,85,83,65,90,77,85};int*p=a;max=*p;for(;p<&a[10];p++)if(*p>max)max=*p;cout<<"max="<voidmain(){intn,k=1,s=0,m;for(n=1;n<=100;n++){k=1;s=0;1m=n;while(2m){4、k*=m%10;s+=m%10;3m/=10;}if(k>s)cout<voidmain(){doubles;inti,n;cout<<"n=";cin>>n;s=0;for(i=1;i5、e*next;};create(node*head){node*p,*q;p=newnode;cin>>p->data;q=p;while(p->data){if(head==NULL)head=p;elseq->next=p;;q=p;p=newnode;;cin>>p->data;}q->next=NULL;deletep;}}5.以下程序求方程的全部整数解:3x+2y-7z=5(0≤x,y,z≤100)#includevoidmain(){intx,y,z;for(x=0;x<=100;x++)for(y=0;y<6、=100;y++){if((z=3*x+2*y-5)%7)break;z=3*x+2*y-5)/7;//求出z的值if(z<=100&&z>=0)//检查z的范围cout<<"x="<voidmain(){inti,n;for(i=0;i<5;i++){for(n=0;n<2*i-1;n++){cout<7、;}}2.请编程序,输入两个正整数啊a和b(ausingnamespacestd;voidprintFactor(inti);voidmain(){intnumA,numB;cout<<"InputTwoNumbers:"<>numA>>numB;for(in8、ti=numA;i<=numB;i++){printFactor(i);}}voidprintFactor(inti){cout<<"FACTORSO
2、#includeintfun(intn){if(n==0)return1;return2*fun(n-1);}voidmain(){inta=5;cout<voidmain(){char*cp="word";for(inti=0;i<4;i++)cout<voidmain(){i
3、ntmax;inta[10]={76,55,95,87,85,83,65,90,77,85};int*p=a;max=*p;for(;p<&a[10];p++)if(*p>max)max=*p;cout<<"max="<voidmain(){intn,k=1,s=0,m;for(n=1;n<=100;n++){k=1;s=0;1m=n;while(2m){
4、k*=m%10;s+=m%10;3m/=10;}if(k>s)cout<voidmain(){doubles;inti,n;cout<<"n=";cin>>n;s=0;for(i=1;i5、e*next;};create(node*head){node*p,*q;p=newnode;cin>>p->data;q=p;while(p->data){if(head==NULL)head=p;elseq->next=p;;q=p;p=newnode;;cin>>p->data;}q->next=NULL;deletep;}}5.以下程序求方程的全部整数解:3x+2y-7z=5(0≤x,y,z≤100)#includevoidmain(){intx,y,z;for(x=0;x<=100;x++)for(y=0;y<6、=100;y++){if((z=3*x+2*y-5)%7)break;z=3*x+2*y-5)/7;//求出z的值if(z<=100&&z>=0)//检查z的范围cout<<"x="<voidmain(){inti,n;for(i=0;i<5;i++){for(n=0;n<2*i-1;n++){cout<7、;}}2.请编程序,输入两个正整数啊a和b(ausingnamespacestd;voidprintFactor(inti);voidmain(){intnumA,numB;cout<<"InputTwoNumbers:"<>numA>>numB;for(in8、ti=numA;i<=numB;i++){printFactor(i);}}voidprintFactor(inti){cout<<"FACTORSO
5、e*next;};create(node*head){node*p,*q;p=newnode;cin>>p->data;q=p;while(p->data){if(head==NULL)head=p;elseq->next=p;;q=p;p=newnode;;cin>>p->data;}q->next=NULL;deletep;}}5.以下程序求方程的全部整数解:3x+2y-7z=5(0≤x,y,z≤100)#includevoidmain(){intx,y,z;for(x=0;x<=100;x++)for(y=0;y<
6、=100;y++){if((z=3*x+2*y-5)%7)break;z=3*x+2*y-5)/7;//求出z的值if(z<=100&&z>=0)//检查z的范围cout<<"x="<voidmain(){inti,n;for(i=0;i<5;i++){for(n=0;n<2*i-1;n++){cout<7、;}}2.请编程序,输入两个正整数啊a和b(ausingnamespacestd;voidprintFactor(inti);voidmain(){intnumA,numB;cout<<"InputTwoNumbers:"<>numA>>numB;for(in8、ti=numA;i<=numB;i++){printFactor(i);}}voidprintFactor(inti){cout<<"FACTORSO
7、;}}2.请编程序,输入两个正整数啊a和b(ausingnamespacestd;voidprintFactor(inti);voidmain(){intnumA,numB;cout<<"InputTwoNumbers:"<>numA>>numB;for(in
8、ti=numA;i<=numB;i++){printFactor(i);}}voidprintFactor(inti){cout<<"FACTORSO
此文档下载收益归作者所有