Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Sorting an array by enumeration and in the same array in C

I wrote a program but it is not running in the right way. Could you help me with a good solution for that?

int main()
{
    int t[8]={5,3,4,1,5,2,5,10},i=0,n=0,j,c;

    do{
        for(j=i+1;j<8;j++){
                if(t[i]>t[j]){
            n=n+1;
            }
        }
        if(n==0){
            i++;
        }else{
            if(t[i]!=t[n+i]){
                c=t[i];
                t[i]=t[n+i];
                t[n+i]=c;
            }else{
                do{
                    n++;
                }while(t[i]=t[n+i]);
                c=t[i];
                t[i]=t[n+i];
                t[n+i]=c;
            }
        }
    n=0;
    }while(i<7);
    for(j=0;j<8;j++){
        printf("element %d is : %d\n",j+1,t[j]);
    }
    return 0;

Comments