All pastes #826145 Raw Edit

Unnamed

public cpp v1 · immutable
#826145 ·published 2007-12-21 00:52 UTC
rendered paste body
 /** * * @File    : TrianglePascalV1.cxx * * @Author  : D. Mathieu *  * @Date    : 17/10/2007 * * Synopsys : Triangle de Pascal : Version 1 (utilisation de vectors) ***/#include <iostream>#include <vector>#include <iomanip>       // setw()using namespace std;#define classdef typedefnamespace{    classdef vector <unsigned>  CVUInt;    classdef vector <CVUInt>    CVVUInt;    typedef  CVUInt::size_type  IndV_t;    typedef  CVVUInt::size_type IndVV_t;    CVUInt LigneTrianglePascalV1 (const CVVUInt & TrianglePascal,                                   IndVV_t N)    {        if (N < TrianglePascal.size())            return TrianglePascal [N];        else            return CVUInt ();    } // LigneTrianglePascalV1()    void GenerTrianglePascalV1 (CVVUInt & TrianglePascal, IndVV_t N)    {        TrianglePascal.clear();        TrianglePascal.reserve (N + 1);        // Ligne 0        TrianglePascal.push_back (CVUInt (1, 1));        for (IndVV_t Li = 1; Li <= N; ++Li)        {            TrianglePascal.push_back (CVUInt (Li + 1, 1));            for (IndV_t Col = 1; Col < Li; ++Col)                TrianglePascal [Li ][Col] =                            TrianglePascal [Li - 1][Col - 1] +                            TrianglePascal [Li - 1][Col    ];        }                } // GenerTrianglePascalV1()    void TrianglePascalV1 ()    {        cout << "Triangle de Pascal\n\n";        CVVUInt TrianglePascal;        unsigned NbLignes;        cout << "Numéro de la dernière ligne : ";        cin >> NbLignes;        GenerTrianglePascalV1 (TrianglePascal, NbLignes);        for (unsigned i = 0; i <= NbLignes; ++i)        {            for (unsigned j = 0; j <= i; ++j)                cout << setw (4) << TrianglePascal [i][j];            cout << '\n';        }        {            IndVV_t NumLigne;            CVUInt Ligne;                        for (cout <<    "Ligne : ", cin >> NumLigne;                  !cin.eof();                  cout << "\n Ligne : ", cin >> NumLigne)            {                Ligne = LigneTrianglePascalV1 (TrianglePascal, NumLigne);                for (unsigned j = 0; j < Ligne.size(); )                    cout << setw (4) << Ligne [j++];            }            cout << '\n';        }    } // TrianglePascalV1()} // namespace anonymeint main (){    /*   */ TrianglePascalV1();  /*   */        return 0;} // main()