杨辉三角形

#include<iostream>
#include<string>


using namespace std;


void view(int rows);


int main(int argc,char** argv){

int nums;
cin >> nums;

view(nums);

return 0;
}


void view(int rows){

int data[rows][rows];

for(int i = 0;i < rows;i++){

for(int j = 0;j < rows;j++){

data[i][j] = 0;
}
}

for(int i = 0;i < rows;i++){

for(int j = 0;j < rows;j++){

if(j == 0 || i == j){

data[i][j] = 1;

}else{

if(i > 0){

data[i][j] = data[i - 1][j - 1] + data[i - 1][j];

}
}
}
}


for(int i = 0;i < rows;i++){

for(int j = 0;j < rows;j++){

if(data[i][j] != 0){

cout  << data[i][j] << " ";
}
}

cout << endl;
}
}

猜你喜欢

转载自blog.csdn.net/itlanyue/article/details/80368530