#include "stdafx.h"
#include<iostream>
using namespace std;
#include <iomanip>
//写一个函数,通过调用函数,实现打印输出杨辉三角的前10行
int _tmain(int argc, _TCHAR* argv[])
{
int yanghui[10][10],i,j;
void yanghuiTriangle(int yh[][10]);
yanghuiTriangle(yanghui);
cout<<"杨辉三角的前10行为:"<<endl;
for(i=0;i<10;i++)
{for(j=0;j<=i;j++)
cout<<setw(3)<<yanghui[i][j]<<" ";
cout<<endl;
}
cout<<endl;
return 0;
}
//杨辉三角函数
void yanghuiTriangle(int yh[][10])
{
int i,j;
for(i=0;i<10;i++)
for(j=0;j<=i;j++)
if(j==0||i==j) yh[i][j]=1;
else yh[i][j]=yh[i-1][j-1]+yh[i-1][j];
}
c++实现输出杨辉三角
猜你喜欢
转载自blog.csdn.net/qq_43090158/article/details/86211005
今日推荐
周排行