您的位置:首页 > 编程语言 > C语言/C++

C++第4作业

2016-04-26 22:17 162 查看
1、计算机解奥数

#include <iostream>
using namespace std;
int main()
{
int e,b,c,d;
int  x,u,v,y;
for(b=0; b<=2; b++)
for(c=0; c<=9; c++)
for(d=0; d<=9; d++)
for(e=0; e<=9; e++)
{
x=d*10+e;
u=c*100+d*10+e;
v=b*1000+c*100+d*10+e;
y=x+u+v+e;
if(y==2008&&e!=c&&e!=b&&e!=d)
cout<<"都:"<<b<<"\t"<<"要:"<<c<<"\t"<<"学:"<<d<<"\t"<<"C:"<<e<<endl;
}
return 0;
}
运行结果



2、百钱百鸡问题

#include <iostream>
using namespace std;
int main()
{
int a,b,c;
int n=0;
for(a=3; a>=3&&a<=300; a+=3)
for(b=0; b<=33; b++)
for(c=0; c<=20; c++)
if(a/3+3*b+5*c==100&&a+b+c==100)
{
n++;
cout<<"第"<<n<<"种:\t"<<"雏鸡"<<a<<"个,母鸡"<<b<<"个,公鸡"<<c<<"个\n";
}
cout<<"共有"<<n<<"种\n";
return 0;
}


运行结果



3、输出星形图

#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,e;
for(d=1; d<=5; d++)
cout<<" ";
cout<<"*";
cout<<endl;
for(a=1; a<=4; a++)
{
for(b=1; b<=5-a; b++)
cout<<" ";
cout<<"*";
for(c=1; c<=2*a-1; c++)
cout<<" ";
cout<<"*";
cout<<endl;
}

for(e=1; e<=11; e++)
cout<<"*";
return 0;
}


运行结果



4、九九乘法表

#include <iostream>
using namespace std;
int main()
{
int a,b;
for(a=1; a<=9; a++)
{
for(b=1; b<=a; b++)

cout<<b<<"x"<<a<<"="<<a*b<<"\t";

cout<<endl;
}

return 0;
}


运行结果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: