编写一个函数void funint p int n其功能为对整数数组p5中的数字进行排序。排序结果在主函数中输出。 输入: 34 78 23 12 69 输出如下: 7869342312使用c语言
#include <stdio.h>
void fun(int *p, int n);
int main() { int arr[5] = {34, 78, 23, 12, 69}; fun(arr, 5); for(int i = 0; i < 5; i++) { printf("%d,", arr[i]); } return 0; }
void fun(int *p, int n) { int temp; for(int i = 0; i < n-1; i++) { for(int j = 0; j < n-i-1; j++) { if(p[j] < p[j+1]) { temp = p[j]; p[j] = p[j+1]; p[j+1] = temp; } } } }
原文地址: https://www.cveoy.top/t/topic/daMn 著作权归作者所有。请勿转载和采集!