#include<stdio.h>
#include <stdlib.h>
#include <stdlib.h>
void sort_num(int num[5], int n);
void print_num(int num[5], int n);
void print_num(int num[5], int n);
int main()
{
int num[5] = { 1, 5, 3, 2, 9 };
sort_num(num, sizeof(num) / sizeof(num[0]));
print_num(num, sizeof(num) / sizeof(num[0]));
{
int num[5] = { 1, 5, 3, 2, 9 };
sort_num(num, sizeof(num) / sizeof(num[0]));
print_num(num, sizeof(num) / sizeof(num[0]));
system("pause");
return 0;
return 0;
}
void sort_num(int num[5],int n)
{
int i = 0;
int j = 0;
int temp = 0;
for (i = 0; i < n-1; i++)
{
for (j = 0; j < n - i - 1;j++)
if (num[j]<num[j + 1])
{
temp = num[j];
num[j] = num[j + 1];
num[j + 1] = temp;
}
}
}
//void print_num(int num[5], int n)//数组做函数参数会退化为指针,5在这里无意义
//void print_num(int num[], int n)//数组形式写法
void print_num(int *num, int n)//指针形式写法
{
int i = 0;
int j = 0;
for (i = 0; i < n; i++)
{
printf("%d ", num[i]);
}
}
{
int i = 0;
int j = 0;
int temp = 0;
for (i = 0; i < n-1; i++)
{
for (j = 0; j < n - i - 1;j++)
if (num[j]<num[j + 1])
{
temp = num[j];
num[j] = num[j + 1];
num[j + 1] = temp;
}
}
}
//void print_num(int num[5], int n)//数组做函数参数会退化为指针,5在这里无意义
//void print_num(int num[], int n)//数组形式写法
void print_num(int *num, int n)//指针形式写法
{
int i = 0;
int j = 0;
for (i = 0; i < n; i++)
{
printf("%d ", num[i]);
}
}