C++作业4
2016-04-26 22:57
225 查看
乘法口诀表
输出星号图
穷举法解决组合问题
#include<iostream> using namespace std; int main() { int x,y,m,n; for(x=0;x<10;x++) { for(y=0;y<x;y++) { m=y+1; n=x*m; cout<<m<<"*"<<x<<"="<<n<<' '; } cout<<endl; } return 0; }
输出星号图
#include<iostream> using namespace std; void main() { int a,b,c,d,e; for(a=0;a<=4;a++) cout<<" "; cout<<"*"; cout<<endl; for(b=0;b<=3;b++) { for(c=0;c<4-b;c++) cout<<" "; cout<<"*"; for(d=0;d<=2*b;d++) cout<<" "; cout<<"*"; cout<<endl; } for(e=0;e<=10;e++) cout<<"*"; cout<<endl; }
穷举法解决组合问题
#include<iostream> using namespace std; void main() { double b,c,d; for(b=0;b<=20;b++) for(c=0;c<=33;c++) for(d=0;d<=300;d++) if(5*b+3*c+d/3==100 && b+c+d==100) cout<<"鸡翁"<<b<<"只 鸡母"<<c<<"只 鸡雏"<<d<<"只\n"; }
相关文章推荐