# 我的排序出了問題 幫我看一下

#include <stdio.h> #include <stdlib.h> int inp[5], arrayLength, flag, array[5], temp; double sum=0.0; int main() { printf("輸入五個數字(數字間必須空格): "); scanf("%d %d %d %d %d", &inp[0], &inp[1], &inp[2], &inp[3], &inp[4]); for(int i=0; i<5; i++) { ... show more #include <stdio.h>
#include <stdlib.h>

int inp[5], arrayLength, flag, array[5], temp;
double sum=0.0;

int main()
{
printf("輸入五個數字(數字間必須空格): ");
scanf("%d %d %d %d %d", &inp[0], &inp[1], &inp[2], &inp[3], &inp[4]);

for(int i=0; i<5; i++)
{
sum += inp[i];
}

for(int i=0; i<5; i++)
{
printf("Element %d is %d account for %1.2f\n", i, inp[i], (double)(inp[i]/sum)*100 );
}

for(int i=1; (i <= arrayLength) && flag; i++)
{
flag = 0;
for(int j=0; j < (arrayLength - 1); j++)
{
if(array[j+1] > array[j])
{
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
flag = 1;
}
}
}

for(int j=0; j<5; j++)
{
printf("%d\n", array[j]);
}

system("pause");
}
Update: 可是這樣排序出來的結果還是錯的呀....
Update 2: 輸入五個數字(數字間必須空格): 2 5 8 4 6
Element 0 is 2 account for 8.00
Element 1 is 5 account for 20.00
Element 2 is 8 account for 32.00
Element 3 is 4 account for 16.00
Element 4 is 6 account for 24.00
8
6
5
4
2