Toggle navigation
Home
Latest pastes
FAQ
Random
Register
Login
Paskal
SUBMITTED BY:
itsDaveLad
DATE:
March 9, 2016, 5:15 p.m.
FORMAT:
Text only
SIZE:
803 Bytes
Raw
Download
Tweet
HITS:
581
Go to comments
Report
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> f(int n){
vector<vector<int>>mat;
mat.resize(n);
for(int i=0;i<mat.size();i++)
mat[i].resize(i+1);
for(int i=0;i<mat.size();i++){
for(int j=0;j<mat[i].size();j++){
if(i==0 || j==0) mat[i][j]=1;
else
mat[i][j]=mat[i-1][j]+mat[i-1][j-1];
}
}
return mat;
}
int main() {
vector<vector<int>>m;
int a;
cin>>a;
m=f(a);
for(int i=0;i<m.size();i++){
for(int j=0;j<m[i].size();j++){
cout<<m[i][j]<<" ";
}cout<<endl;
}
return 0;
}
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus