欢迎来到天天文库
浏览记录
ID:53123353
大小:104.50 KB
页数:24页
时间:2020-04-01
《C++循环控制结构练习题.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、循环控制结构练习题1.从键盘上输入一个正整数n,计算其阶乘n!#include#includeusingnamespacestd;intf(intn){intt=1;for(inti=n;i>0;i--)t=t*i;returnt;(0的阶层为1)}intmain(){intn;cout<<"n=";cin>>n;cout<2、ude#includeusingnamespacestd;voidf(intn){intk=sqrt(n),i;for(i=2;i<=k;i++)if(n%i==0)break;if(i>=k+1)cout<>n;f(n);system("pause");return0;}法2;#include#includeusingname3、spacestd;boolf(intn){intk=sqrt(n),i;for(i=2;i<=k;i++)if(n%i==0)break;if(i>=k+1)return1;elsereturn0;}intmain(){intn;cout<<"n=";cin>>n;f(n);if(f(n))cout<4、%i==0)return0;if(i>=k+1)return1;1}intmain(){intn;while(1){cin>>n;if(n==0)break;if(f2(n))cout<<"是素数!!"<#includeusingnamespacestd;intf(intn){intt=0;for(inti=n;i>0;i=i/10)t=i%10+t;returnt;}intmain(){5、intn;cout<<"n=";cin>>n;if(n<0)n=abs(n);cout<<"n的各位数字和为:"<>n;if(n<0)n=abs(n);cout<<"n的各位数字和为:"<6、{n=abs(n);if(n<10)returnn;elsereturn((n%10)+f3(n/10));}intmain(){intn;while(1){cin>>n;if(n==0)break;cout<usingnamespacestd;intf(intn){if(n<10)returnn;elsereturn((n%10)*f(n/10));}intmain(){intn;co7、ut<<"n=";cin>>n;n=abs(n);cout<usingnamespacestd;intf(intn){intt=1;for(inti=n;i>0;i=i/10)t=t*(i%10);returnt;}intmain(){intn;cout<<"n=";cin>>n;n=abs(n);cout<8、returnn;elsereturn((n%10)*f3(n/10));}intmain(){intn;while(1){cin>>n;
2、ude#includeusingnamespacestd;voidf(intn){intk=sqrt(n),i;for(i=2;i<=k;i++)if(n%i==0)break;if(i>=k+1)cout<>n;f(n);system("pause");return0;}法2;#include#includeusingname
3、spacestd;boolf(intn){intk=sqrt(n),i;for(i=2;i<=k;i++)if(n%i==0)break;if(i>=k+1)return1;elsereturn0;}intmain(){intn;cout<<"n=";cin>>n;f(n);if(f(n))cout<4、%i==0)return0;if(i>=k+1)return1;1}intmain(){intn;while(1){cin>>n;if(n==0)break;if(f2(n))cout<<"是素数!!"<#includeusingnamespacestd;intf(intn){intt=0;for(inti=n;i>0;i=i/10)t=i%10+t;returnt;}intmain(){5、intn;cout<<"n=";cin>>n;if(n<0)n=abs(n);cout<<"n的各位数字和为:"<>n;if(n<0)n=abs(n);cout<<"n的各位数字和为:"<6、{n=abs(n);if(n<10)returnn;elsereturn((n%10)+f3(n/10));}intmain(){intn;while(1){cin>>n;if(n==0)break;cout<usingnamespacestd;intf(intn){if(n<10)returnn;elsereturn((n%10)*f(n/10));}intmain(){intn;co7、ut<<"n=";cin>>n;n=abs(n);cout<usingnamespacestd;intf(intn){intt=1;for(inti=n;i>0;i=i/10)t=t*(i%10);returnt;}intmain(){intn;cout<<"n=";cin>>n;n=abs(n);cout<8、returnn;elsereturn((n%10)*f3(n/10));}intmain(){intn;while(1){cin>>n;
4、%i==0)return0;if(i>=k+1)return1;1}intmain(){intn;while(1){cin>>n;if(n==0)break;if(f2(n))cout<<"是素数!!"<#includeusingnamespacestd;intf(intn){intt=0;for(inti=n;i>0;i=i/10)t=i%10+t;returnt;}intmain(){
5、intn;cout<<"n=";cin>>n;if(n<0)n=abs(n);cout<<"n的各位数字和为:"<>n;if(n<0)n=abs(n);cout<<"n的各位数字和为:"<6、{n=abs(n);if(n<10)returnn;elsereturn((n%10)+f3(n/10));}intmain(){intn;while(1){cin>>n;if(n==0)break;cout<usingnamespacestd;intf(intn){if(n<10)returnn;elsereturn((n%10)*f(n/10));}intmain(){intn;co7、ut<<"n=";cin>>n;n=abs(n);cout<usingnamespacestd;intf(intn){intt=1;for(inti=n;i>0;i=i/10)t=t*(i%10);returnt;}intmain(){intn;cout<<"n=";cin>>n;n=abs(n);cout<8、returnn;elsereturn((n%10)*f3(n/10));}intmain(){intn;while(1){cin>>n;
6、{n=abs(n);if(n<10)returnn;elsereturn((n%10)+f3(n/10));}intmain(){intn;while(1){cin>>n;if(n==0)break;cout<usingnamespacestd;intf(intn){if(n<10)returnn;elsereturn((n%10)*f(n/10));}intmain(){intn;co
7、ut<<"n=";cin>>n;n=abs(n);cout<usingnamespacestd;intf(intn){intt=1;for(inti=n;i>0;i=i/10)t=t*(i%10);returnt;}intmain(){intn;cout<<"n=";cin>>n;n=abs(n);cout<8、returnn;elsereturn((n%10)*f3(n/10));}intmain(){intn;while(1){cin>>n;
8、returnn;elsereturn((n%10)*f3(n/10));}intmain(){intn;while(1){cin>>n;
此文档下载收益归作者所有