C++
#include<iostream> using namespace std; int fac(int n) { if(n==0) return 1; else return n*fac(n-1); } int combi(int n,int k) { return fac(n)/(fac(k)*fac(n-k)); } int main() { cout<<"몇 줄?"; int line; cin>>line; int i,j; for(i=0;i<line;i++) { for(j=0;j<line-i;j++) cout<<" "; for(j=0;j<=i;j++) cout<<combi(i,j)<<" "; cout<<endl; } return 0; }
- Python
def fac(n): if(n==0): return 1 else: return n*fac(n-1) def combi(n,k): return fac(n)/(fac(k)*fac(n-k)) def pascal(n): for i in range(0,n,1): for j in range(0,n-i,1): print "", for j in range(0,i+1,1): print combi(i,j), print "\n" n=input("줄 수") pascal(n)