Báo Cáo Môn Ngôn Ngữ Lập Trình

Embed Size (px)

Citation preview

  • 8/10/2019 Bo Co Mn Ngn Ng Lp Trnh

    1/11

    Bi 1: Gii nghim phng trnh bc 2

    #include#includeusingnamespacestd;intmain(){

    doublea, b, c, d;cout > a;cout > b;cout > c;d = b*b - 4 * a*c; a *= 2;if(d < 0) cout

  • 8/10/2019 Bo Co Mn Ngn Ng Lp Trnh

    2/11

    if(j == 6) { cout

  • 8/10/2019 Bo Co Mn Ngn Ng Lp Trnh

    3/11

    {d2++;if((A[i] & 7) == 0) d8++;

    }}

    cout

  • 8/10/2019 Bo Co Mn Ngn Ng Lp Trnh

    4/11

    while(S[lin]) lin++;cout s[i];}//delete [] s;

    correct(s);for(inti = 0; i < 15; i++) cout

  • 8/10/2019 Bo Co Mn Ngn Ng Lp Trnh

    5/11

    Bi 8: InsertionSort

    #includeusingnamespacestd;voidmain(){

    intA[] = { 22, 33, 66, 55, 44, 11 };for(inti = 1; i < 6; i++){

    intj = i - 1; inte = A[i];while(j >= 0 && A[j]>e) A[j + 1] = A[j--];A[j + 1] = e;

    }for(inti = 0; i < 6; i++) { cout

  • 8/10/2019 Bo Co Mn Ngn Ng Lp Trnh

    6/11

    }cout

  • 8/10/2019 Bo Co Mn Ngn Ng Lp Trnh

    7/11

    Bi 11: In Part

    #includeusingnamespacestd;intPart(inta[], intl, intr)

    { inti = l+ 1;intj = r;while(j >= i){

    while(i

  • 8/10/2019 Bo Co Mn Ngn Ng Lp Trnh

    8/11

    }voidBuildHeap(intA[], intN, inti, intIndies[]){

    intl = 2 * i+ 1, r = 2 * i+ 2, great;if((lA[Indies[i]])) great = l;

    elsegreat = i;if((rA[Indies[great]])) great = r;if(great != i){

    Swap(Indies[i], Indies[great]);BuildHeap(A, N, great, Indies);

    }}voidHeapSort(intA[], intN, intIndies[]){

    inti;

    for(i = (N- 1) / 2; i >= 0; i--)BuildHeap(A, N, i, Indies);

    for(i = N- 1; i>0; i--){

    Swap(Indies[0], Indies[i]);BuildHeap(A, i, 0, Indies);

    }}intmain(){

    intN, i, j, *A, *Indies;

    do{

    cout N;if(N

  • 8/10/2019 Bo Co Mn Ngn Ng Lp Trnh

    9/11

    for(j = 0; j

  • 8/10/2019 Bo Co Mn Ngn Ng Lp Trnh

    10/11

    {A[j + 1] = A[j];j--;

    }A[j + 1] = e;

    }}voidBubbleSort(){

    for(inti = 0; i < N - 1; i++){

    intc = 0;for(intj = N - 1; j >= i + 1; j--)if(Compare(A[j - 1], A[j]) == 1){

    Swap(A[j - 1], A[j]);

    c = 1;}if(c == 0) return;

    }}intPart(intA[], intl, intr){

    inti = l+ 1, j = r;while(i

  • 8/10/2019 Bo Co Mn Ngn Ng Lp Trnh

    11/11

    }voidCoppy(){

    for(inti = 0; i < N; i++)A[i] = Org[i];

    }voidPrint(){

    for(inti = 0; i < N; i++)cout