当前位置:网站首页>C语言:随机生成数+选择排序
C语言:随机生成数+选择排序
2022-07-25 21:50:00 【念迟鱼学编程】
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAXSIZE 10
void initArr(int arr[] , int length);
void showArr(int arr[] , int length);
void selectSort(int arr[] , int length);
int main()
{
srand((unsigned int)time(NULL));
int arr[MAXSIZE];
printf("==========排序前的序列=============\n");
initArr(arr,MAXSIZE);
showArr(arr,MAXSIZE);
printf("==========选择排序后的序列=============\n");
selectSort(arr,MAXSIZE);
showArr(arr,MAXSIZE);
system("pause");
return 0;
}
void initArr(int arr[] , int length)
{
for(int i = 0 ; i < length ; i++){
arr[i] = rand()%20;
}
}
void showArr(int arr[] , int length)
{
for(int i = 0 ; i < length ; i++){
printf("%4d",arr[i]);
}
printf("\n");
}
void selectSort(int arr[] , int length)
{
//选择排序
for(int i = 0 ; i < length ; i++){
int k = i;
for(int j = i ; j < length ; j++){
if(arr[k] > arr[j]){
k = j;
}
}
int temp = arr[i];
arr[i] = arr[k];
arr[k] = temp;
}
}
边栏推荐
- 【饭谈】细说:下克上,向上管理,向上画饼。
- Automatic assembly and fuse degradation of feign
- Shopify sellers: share some tips for social media marketing!
- Redis 使用详解
- Redis usage details
- Tesseract OCR初探
- 8000 word super detailed custom structure type
- 【饭谈】Web3.0到来后,测试人员该何去何从?(十条预言和建议)
- c sqlite ... ...
- CNN structural design skills: taking into account speed accuracy and engineering implementation
猜你喜欢

2022最新软件测试八股文,能不能拿心仪Offer就看你背得怎样了

Shopify sellers: share some tips for social media marketing!

6-17漏洞利用-反序列化远程命令执行漏洞

Babbitt | metauniverse daily must read: the popularity of virtual people has decreased, and some "debut is the peak", and the onlookers have dispersed
![[Flink] flick rocksdbliststate reports an error you cannot add null to a liststate](/img/c0/1923e17f166ab4bc7d20f48398f366.jpg)
[Flink] flick rocksdbliststate reports an error you cannot add null to a liststate

2022 love analysis ― bank digitalization practice report

Basic knowledge in the project

Redis usage details
![[leetcode ladder] linked list · 021 merge two ordered linked lists](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[leetcode ladder] linked list · 021 merge two ordered linked lists

【Flink】FLink RocksDBListState 报错 You cannot add null to a ListState
随机推荐
How to implement distributed locks with redis?
Special class design
[interview: concurrent Part 24: multithreading: comprehensive exercise] sequence control
2022 love analysis ― bank digitalization practice report
c sqlite ... ...
2022-07-18: what is the output of the following go language code? A:Groutine; B:Main; C:Goroutine; D:GoroutineMain。 package m
I/o case practice
【leetcode天梯】链表 · 021 合并两个有序链表
【饭谈】细说:下克上,向上管理,向上画饼。
GPON introduction and Huawei OLT gateway registration and configuration process
JSP初识
Is there any document for synchronizing from Oracle to ODPs?
我也是醉了,Eureka 延迟注册还有这个坑!
Research on the scheme of MySQL advanced (VIII) sorting problem
redis主从架构锁失效问题(主从)
Share | intelligent fire emergency management platform solution (PDF attached)
[interview: concurrent Article 23: multithreading: Join] re understanding of join
How to evaluate hardware resources (number of CPUs, memory size) when Oracle migrates from small computers to x86 architecture? Is there a measurement index or company?
开源协议是否具有法律效力?
C#常见的集合