U E D R , A S I H C RSS

파스칼삼각형/aekae

파스칼삼각형 배열 이용

~cpp 
#include <iostream>
using namespace std;

const int MAX = 100;

int main()
{
	int arr[MAX][MAX];
	for (int i=1; i<MAX; i++)
	{
		arr[i][1] = 1;
		arr[i][i] = 1;
	}
	int j,k;
	for (j=2; j<MAX; j++)
	{
		for (k=1; k<MAX; k++)
		{
			if (j+1 == k+1)
				break;
			arr[j+1][k+1] = arr[j][k] + arr[j][k+1];
		}
	}
		
	int row,col;	
	cout << "행과 열을 입력: ";
	cin >> row >> col;
	cout << arr[row][col] << endl;

	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.2032 sec