Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

파스칼삼각형/김홍기: Difference between revisions

From ZeroWiki
imported>sibichi
No edit summary
(Repair batch-0008 pages from live compare)
 
Line 33: Line 33:
  cout<<PasNum(col-1,row-1)<<endl;
  cout<<PasNum(col-1,row-1)<<endl;
  }
  }

Latest revision as of 01:40, 27 March 2026

후기

  • 첨엔 파스칼삼각형을 출력하라는 줄 알았던 -_-;
  • 그리고나서 좌표구하는건 팩토리얼이라는걸 떠올려서 재귀함수로 도전
  • 그런데 재귀함수쓰니 뭔가 이상한 문제가 나와서 그냥 포문활용

소스

#include <iostream>

using namespace std;

int PasNum(int col,int row){
	int i=0;
	int result=1;
	for(i=0;i<row;i++){
		result*=col;
		col--;
	}
	for(i=0;i<row;i++){
		result/=row;
		row--;
	}
	return result;
}
void main(){
	int col, row;
	cout<<"파스칼삼각형의 숫자 확인"<<endl;
	cout<<"행은?";
	cin>>col;
	cout<<"열은?";
	cin>>row;
	
	cout<<PasNum(col-1,row-1)<<endl;
}