求線型代數逆序數的代碼!

如輸入54321 逆序數是10⋯⋯⋯⋯用c語言⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯

 #include<stdio.h>

int getResult(int* array, int dataNum);

int main()
{
    int array[105];
    int dataNum, i, res;
    while(true)
    {
        printf("请输入数据个数:\n");
        scanf("%d", &dataNum);
        printf("请输入数据,以空格隔开:\n");
        for(i = 0; i < dataNum; i++)
            scanf("%d", &array[i]);
        res = getResult(array, dataNum);
        printf("逆序数为:%d\n", res);
    }
    return 0;
}

int getResult(int* array, int dataNum)
{
    int i, j, res = 0;
    for(i = 1; i < dataNum; i++)
    {
        for(j = 0; j < i; j++)
        {
            if(array[i] < array[j])
                res ++;
        }
    }
    return res;
}

不好意思,回来晚了~
你要是想要的话就拿去测试吧~10位数以内应该是没问题的,自己改NUM就可以了~

#include<stdio.h>
#define NUM 10 //or whaterver you like 

int main() {
    int num,j,i=0,rev=0,count=0; //num is what you input,i and j is loop variable,rev is as output and count is the size of input num
    int array[NUM],temp_arr[NUM];

    printf("Please input the num whose reverse number is needed:\n");
    scanf("%d",&num);

    int temp = num;               //Depart number as isolated num : 54321 -> 1 2 3 4 5 in array for instance
    while(temp/10 != 0) {
        temp_arr[i] = temp % 10;
        temp = temp / 10;
        i++;
    }
    temp_arr[i] = temp % 10;
    count = i + 1;

    j = count - 1;               //Change 1 2 3 4 5 -> 5 4 3 2 1 for instance
    for(i = 0;i < count;i++) {
        array[i] = temp_arr[j];
        j--;
    }

    for(i = 0;i < count-1;i++)        //Compare and compute rev as output
        for (j = i+1;j <count;j++) {
            if (array[i] > array[j])
                rev++;
        }

    printf("The corresponding reverse num is %d!\n",rev);
    return 0;

}