열혈강의C 16 도전5 배열 내림차순 정리함수

#include <stdio.h>

void DesSort(int*pArr);
int main(void)
{
int arr[7]={1, 2, 3, 5, 6, 7, 8};
int i;
printf("n1-%d", *arr);
printf("n2-%dn", arr);
printf("3-%dn", arr[0]);
for(i=0; i<7; i++)
{
scanf("%d", &arr[i]);
}
printf("n1-%d", *arr);
printf("n2-%dn", arr);
printf("3-%dn", arr[0]);

DesSort(arr);

for(i=0; i<7; i++)
{
printf(" %d ", arr[i]);
}
return 0;
}
void DesSort(int*pArr)
{
int i,j, temp;
for(j=0; j<6; j++)
{
for(i=0; i<6-j; i++)
{
if (pArr[i]<=pArr[i+1])
{
temp=pArr[i];
pArr[i]=pArr[i+1];
pArr[i+1]=temp;
}
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

 characters available

+ 54 = 62