c++作业4

来源:互联网 发布:廊坊市网络招聘 编辑:程序博客网 时间:2024/06/03 19:04

一,编写乘法表

#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;}


0 0
原创粉丝点击