More actions
imported>yjh0817 No edit summary |
imported>yjh0817 No edit summary |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
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): | def fac(n): | ||
if(n==0): | if(n==0): | ||
| Line 18: | Line 54: | ||
n=input("줄 수") | n=input("줄 수") | ||
pascal(n) | pascal(n) | ||
Latest revision as of 12:02, 2 August 2010
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)