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

c++作业4

2016-04-26 21:46 288 查看
一,编写乘法表

#include <iostream.h>
#include <cmath>
int main()
{

cout << "输出乘法表为" << endl;
for (int a=1;a<=9;a++)
{  for(int b=1;b<=a;b++)
cout << a << "*" << b << "=" << a*b << " "<< '\t';
cout<<endl;
}

return 0;
}


二,穷举法

#include <iostream>
using namespace std;
int main()
{
int a,b,c,n(0);
for(a=0; a<=3; a++)
for(b=0; b<=3; b++)
for(c=0; c<=6; c++)
if(a+b+c==8)
n++;
cout<<"共有"<<n<<"种方法"<<endl;
}


三,三角形图案

#include<iostream>
using namespace std;
int main()
{
int n,i,j;
char ch;
cout<<"多少行的三角形?"<<endl;
cin>>n;
for(i=1;i<=n;i++)
{
for(j=n;j>=i;j--)
cout<<"  ";
for(j=1;j<=2*i-1;j++)
cout<<"*"<<" ";
cout<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: