c++作业4
来源:互联网 发布:java 换行符替换 编辑:程序博客网 时间:2024/06/05 14:55
【项目4:输出完数】
#include <iostream>#include<Cmath>using namespace std;int main( ){ int i,k,j; cout<<"2-1000之间的完数有:"; for(i=2;i<=1000;i++) { k=1; for(j=2;j<sqrt(i);j++) if(i%j==0) k+=(j+i/j); if(i==k) cout<<i<<" "; } cout<<endl; return 0;}
【项目6:输出星号图】
#include <iostream> using namespace std; int main() { int i,j,n; cout<<"请输入行数n:"<<endl; cin>>n; for(i=1;i<n;i++) { cout<<" "; } cout<<"*"<<endl; for(i=2;i<n;i++) { for(j=0;j<n-i;j++) { cout<<" "; } cout<<"*"; for(j=0;j<2*(i-1)-1;j++) { cout<<" "; } cout<<"*"<<endl; } for(j=0;j<=2*i-2;j++) { cout<<"*"; } cout<<endl; return 0; }【项目7:穷举法解决组合问题】
(3)三色球问题
#include<iostream>using namespace std;int main (){int r,w,b;cout<<"不同的颜色搭配有:"<<endl;for(r=0;r<=3;r++)for(w=0;w<=3;w++){b=8-r-w;if(b<=6){cout<<"红球:"<<r<<","<<"白球:"<<w<<","<<"黑球:"<<b<<endl;}}return 0;}
0 0
- C/C++作业4
- C语言程序设计课后作业4
- C语言作业(4)
- c 作业
- c作业
- C作业
- c作业
- c作业
- c作业
- c作业
- c作业
- C++P27作业3,4,5,6
- C++P51作业1,3,4,6
- C语言作业-4-1素数和
- C语言作业-4-2念整数
- XTU C语言程序设计实践作业4
- 11-4c 语言 作业 指针
- 【C语言】【unix c】作业 前台作业和后台作业
- linux postgresql 安装配置详解
- Vitamio与FFmpeg、LGPL、GPL的关系
- Shell 脚本知识回顾 (二) —— Shell变量
- runloop 与autorelase对象、Autorelease Pool 在什么时候释放
- 10、XML约束
- c++作业4
- C++常数/字面量
- mysql的数据库的备份与恢复
- c++语言函数
- poj 1159 && hdu 1513 Palindrome(LCS)
- 1.8.程序的内存分配
- 一篇很不错的介绍jquery的上下文的文章
- 一个软件初学者的唠叨
- C++类型修饰符