当前位置:网站首页>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;
}
}
边栏推荐
- [redis underlying parsing] linked list type
- 【饭谈】那些看似为公司着想,实际却让人无法理解的事(二:面试时的软素质“眼缘”)
- 立创EDA——我为什么要学EDA
- YUV420 yuv420sp image format "recommended collection"
- ORIGYN基金会正式启动$OGY Staking,引领新一轮生态利好
- Shopify sellers: share some tips for social media marketing!
- Naming rules for BSP of Quanzhi chip
- 【leetcode天梯】链表 · 876 查找链表中间结点
- Special symbols in shell
- C#常见的集合
猜你喜欢

Ansible+cronab batch deployment patrol

Bitcoin.com:USDD代表了真正去中心化稳定币
![[redis underlying parsing] string type](/img/a6/47083b033125195ebaf80090919fe2.png)
[redis underlying parsing] string type

Oxford University: many common insomnia drugs lack long-term safety data

Redis 使用详解
![[leetcode ladder] linked list · 876 find the middle node of the linked list](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[leetcode ladder] linked list · 876 find the middle node of the linked list

Redis usage details

C#Socket

Byte side: can TCP and UDP use the same port?
![[database] index](/img/57/4921cf3eee9e8395415a8624b28d0a.png)
[database] index
随机推荐
How to use RS485 half duplex chip correctly
strcpy()
Protobuf的简单使用
Unity metaverse (II), mixamo & animator hybrid tree and animation fusion
性能调试 -- Chrome Performance
In Oracle 19C version, logminer package continuous_ The outdated function of mine leads to CDC failure
mouseEvent事件——mouse坐标描述——focus事件——input事件——节流(thorttle)——mouseWheel(滚轮事件)
C#程序设计的6大原则
PE format: analyze and implement IATHOOK
【测开方法论】测开平台pk心得-抉择
dovecot 设置邮箱quota
YUV420 YUV420sp 图像格式「建议收藏」
[redis underlying parsing] linked list type
H5 realize the animation effect of a scratch card
Jmeter---设置代理录制请求
Vivo official website app full model UI adaptation scheme
Bitcoin.com:USDD代表了真正去中心化稳定币
The noise reduction effect is increased by more than 6 times! With the microphone inside the headset, this wireless noise reduction headset is unusual!
Does the open source agreement have legal effect?
Ijcai2022 meeting! Microsoft and other tutorials on domain generalization