当前位置:网站首页>C language: random generated number + selective sorting
C language: random generated number + selective sorting
2022-07-25 22:00:00 【Nianchi ichthyology programming】
#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("========== The sequence before sorting =============\n");
initArr(arr,MAXSIZE);
showArr(arr,MAXSIZE);
printf("========== Select the sorted sequence =============\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)
{
// Selection sort
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;
}
}
边栏推荐
- 【饭谈】细说:下克上,向上管理,向上画饼。
- Animation curves are used every day. Can you make one by yourself? After reading this article, you will!
- 测试工作不受重视,你换位思考了吗?
- [MAIXPY]kpu: load error:2005, ERR_READ_FILE: read file failed问题解决
- Bitcoin.com:USDD代表了真正去中心化稳定币
- Create files, file permissions, ownership, and sticky bits
- Basic knowledge in the project
- [JS] the problem pointed by this
- Ansible+cronab batch deployment patrol
- c sqlite ... ...
猜你喜欢

少儿编程 电子学会图形化编程等级考试Scratch一级真题解析(判断题)2022年6月

【Flink】FLink RocksDBListState 报错 You cannot add null to a ListState

立创EDA——器件的创建01-电阻(二)

Lichuang EDA -- creation of devices 01 resistance (II)

性能调试 -- Chrome Performance

字节跳动技术面都过了,结果还是被刷了,问HR原因竟是。。。

Open source RSS subscriber freshrss

The automation testing post spent 20K recruiting, but in the end, there was no suitable one. Both fresh students are better than them

面了个腾讯三年经验的测试员,让我见识到了真正的测试天花板

Idea resolves the prompt of profile properties disappear
随机推荐
分享|智慧消防应急管理平台解决方案(附PDF)
性能调试 -- Chrome Performance
Idea resolves the prompt of profile properties disappear
Basic knowledge in the project
Oxford University: many common insomnia drugs lack long-term safety data
【饭谈】软件测试薪资层次和分段(修仙)
五种分配方式是否会产生内部碎片、外部碎片
少儿编程 电子学会图形化编程等级考试Scratch一级真题解析(判断题)2022年6月
面了个腾讯三年经验的测试员,让我见识到了真正的测试天花板
字节跳动技术面都过了,结果还是被刷了,问HR原因竟是。。。
虚拟内存与磁盘
【饭谈】那些看似为公司着想,实际却让人无法理解的事(二:面试时的软素质“眼缘”)
别投了,软件测试岗位饱和了...
JMeter websocket interface test
磁盘空间的三种分配方式
At present, flynk CDC does not support mysql5.5. If you change the source code and release this restriction, there will be a lot of data problems?
Bitcoin.com:USDD代表了真正去中心化稳定币
Lichuang EDA -- creation of devices 01 resistance (II)
JS timer and swiper plug-in
Summary of function test points of wechat sending circle of friends on mobile terminal