Breaking News
Loading...
Thursday, July 11, 2013

Hàm sắp xếp các phàn tử chẳn giảm dần trên mảng 1 chiều

7/11/2013 09:42:00 PM
void sapxepgiam(int a[], int n)
{
    int tam;
    for( int i=0;i<n-1;i++)
        if(a[i]%2==0)
            for( int j=i+1;j<n;j++)
            if (a[i]<a[j] && a[j]%2==0 )
            {
                     tam=a[i];
              a[i]=a[j];
              a[j]=tam;
            }
}

3 comments:

  1. #include
    #include
    #include
    void main(void)
    {
    int a[50],i,n,j,x;
    do
    {
    printf("n= ");
    scanf("%d",&n);
    }while(n<=0 && n>=50);
    for (i=0;ia[j])
    {
    x=a[i];
    a[i]=a[j];
    a[j]=a[i];
    }
    }
    }
    printf("Day so tang dan: ");
    for (i=0;i<n;i++)
    printf("%3d",a[i]);

    getch();
    system("pause");

    }
    Có thể chữa lỗi gjum mình được k? :( Mình mới thử tự học mà làm tới đây k biết lỗi sai ở chổ nào hết..Lấy thuật toán từ pascal qua

    ReplyDelete
  2. for (i=0;ia[j]) : chỗ này sai cú pháp bạn ơi

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete

 
Toggle Footer