Fancy Mouse
- -|||
杨辉三角~~画一个矩阵然后按照定义算吧
#include<iostream>
using namespace std;

#define N 34
void Triangle(int Num);
int main()
{
    
int n,datas=1;
    
while(cin>>n)
    
{
        
if(datas>1) cout<<endl;
        cout
<<"Case "<<datas++<<':'<<endl;
        Triangle(n);
    }

    
return 0;
}

void Triangle(int Num)
{
    
long int a[N][N];
    
int Line,Row;
    
for(Line=0;Line<Num;Line++)
    
{
        
for(Row=0;Row<=Line;Row++)
        
{
            
if(0==Row || Line==Row)
            
{
                a[Line][Row]
=1;
                
if(Line>0 && Line==Row) cout<<' ';
                cout
<<a[Line][Row];
                
continue;
            }

            a[Line][Row] 
= a[Line-1][Row] + a[Line-1][Row-1];
            cout
<<' '<<a[Line][Row];
        }

        cout
<<endl;
    }

}
杨辉三角~~画一个矩阵然后按照定义算吧
posted on 2005-08-21 17:43  Fancy Mouse  阅读(499)  评论(2编辑  收藏  举报