Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[1145] Re:파스칼의 삼각형에 대한겁니다.
진수.네모 [miman101] 1540 읽음    2002-09-10 08:20
//---------------------------------------------------------------------------

#include <vcl.h>
#include <iostream.h>
#include <vector.h>
#include <conio.h>
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
void Calculate( int i );

vector<int> pyra[100];

int main(int argc, char* argv[])
{
    cout <<"    *****   Display Pascal Triangle  *****";

    cout <<"\n\nInput the Line Number : ";
    int LineNum;
    cin >> LineNum;

    for(int i=0 ; i<LineNum ; i++)
    {
        Calculate(i);
    }

    for(int i=0 ; i<LineNum ; i++)
    {
        for( int x=0 ; x<i+1 ; x++)
        {
            cout<<pyra[i].at(x)<<"\t";
        }
        cout<<"\n";
    }
    getch();

    return 0;
}
//---------------------------------------------------------------------------
void Calculate(int LineNum)
{
    if( LineNum == 0 )
    {
        pyra[0].push_back(1);
    }
    else
    {
        pyra[LineNum].push_back(pyra[LineNum-1].at(0));

        for(int i=0; i< LineNum -1 ; i++)
        {
            pyra[LineNum].push_back( pyra[LineNum-1].at(i) + pyra[LineNum-1].at(i+1) );
        }

        pyra[LineNum].push_back(pyra[LineNum-1].at(LineNum-1));
    }

}
//-----------------------------------------------------------------------------


빌더에서 작업한 것이어서 Bc++ 3.1에서는 안돌아 갈수 있음다.

박준호 님이 쓰신 글 :
:       1
:     1  1
:    1  2  1
:  1  3  3  1
: 1 4  6  4   1
:
: 예를 들어 숫자 5를 넣으면 위와같이 되는결과를 내는것인데여...
: 솔직히 레포트 맞습니다. 그런데 제가 문제를 풀긴 했는데.. ㅡ.ㅡ
:
: 고수님들의 좋은 방법이 더 있지 않을까해서 물어보는겁니다.
: 알고리즘, 자료구조 무지 어렵네여.. 고수님들의 좋은 방법 부탁드립니다.
:
: 그리고 밑에는 제가 구현한것입니다.
: #include<stdio.h>
:
: int sum_total(int n)
: {
:     int i, sum = 0;
:
:     for (i = 1; i <= n; i++)
:         sum = sum + i;
:
:     return sum;
: }
:
: void main()
: {
:     int array[100];
:     int i, j, stdLeft, stdRight, index, line, maxLine;
:     line = 1;
:     index = 0;
:
:     scanf("%d", &maxLine);
:
:     if (maxLine > 100)
:     {
:         printf("숫자가 너무 큽니다. 100 이하로 해주십시요");
:         exit(1);
:     }
:
:     for (i = 0; i < 100; i++)
:         array[i] = 0;
:
:     while (line <= maxLine)
:     {
:         for(i = 0; i < (maxLine - line); i++)
:         {
:             printf(" ");
:         }
:         for(j = 1; j <= line; j++)
:         {
:             stdLeft = sum_total(line - 1);
:             stdRight = (stdLeft + line) - 1;
:
:             if ((index - line) <= 0)
:                 array[index] = 1;
:             else if (stdLeft == index)
:             {
:                 array[index] = 1;
:             }
:             else if (stdRight == index)
:             {
:                 array[index] = 1;
:             }
:             else
:                 array[index] = array[index - line] + array[index - line + 1];
:
:             if (array[index] < 10)
:             {
:                 printf(" ");
:             }
:
:             printf("%d", array[index]);
:             printf(" ");
:
:             index++;
:         }
:
:         printf("\n");
:         line++;
:     }
: }
:
: 너무 지저분한것 같네요.. ㅜ,ㅜ
: 한마디로 그냥 기능만 되는.. ㅡ.ㅡ

+ -

관련 글 리스트
1141 파스칼의 삼각형에 대한겁니다. 박준호 1933 2002/09/09
3547     Re:파스칼의 삼각형에 대한겁니다. 김재구 1536 2002/09/09
1145     Re:파스칼의 삼각형에 대한겁니다. 진수.네모 1540 2002/09/10
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.