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

c++作业4

2016-04-27 00:14 351 查看
一、输出星号图

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


乘法表

#include<iostream>
using namespace std;
int main()
{
int i,j;
for( i=1;i<=9;i++)
{
for(j=1;j<=i;j++)
cout<<j<<"*"<<i<<"="<<i*j<<",";
cout<<endl;
}
}


三色球问题



#include<iostream>
using namespace std;
int main()
{
int white,red,black;
cout<<"方案有:"<<endl;
for(white=0;white<=3;white++)
for(red=0;red<=3;red++)
{
black=8-white-red;
if(black>=0&&black<=6)
{
cout<<"white="<<white<<","<<"red="<<red<<","<<"black="<<black<<endl;
}
}



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