当前位置:网站首页>C language: random generated number + bubble sort
C language: random generated number + bubble sort
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 bubsort(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("========== The sorted sequence =============\n");
bubsort(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 bubsort(int arr[] , int length)
{
while(length--){
for(int i = 0 ; i < length ; i++){
if(arr[i+1] < arr[i]){
int temp = arr[i+1];
arr[i+1] = arr[i];
arr[i] = temp;
}
}
}
}
边栏推荐
- How will Web3 change the future of people?
- Idea resolves the prompt of profile properties disappear
- ORIGYN基金会正式启动$OGY Staking,引领新一轮生态利好
- 2022 the latest software tests eight part essay. Whether you can offer depends on how you recite it
- 如何用 Redis 实现分布式锁的?
- 2022最新软件测试八股文,能不能拿心仪Offer就看你背得怎样了
- 如何实现一个App应用程序,限制用户时间使用?
- JSP初识
- Protobuf的简单使用
- [fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
猜你喜欢

5、 Pinda general permission system__ PD tools XXS (anti cross site script attack)

Creation and destruction of function stack frames

PE格式: 分析IatHook并实现

如何实现一个App应用程序,限制用户时间使用?

FAW red flag "King fried" is listed, which is safe and comfortable
![[redis underlying parsing] linked list type](/img/e8/c192629dce1a958155a562d216d532.png)
[redis underlying parsing] linked list type

2 lines of code to generate a solid desktop background

Bitcoin.com:USDD代表了真正去中心化稳定币

如何用 Redis 实现分布式锁的?

信息安全建设原则指导
随机推荐
2年功能测试,却感觉自己什么都不会,2022我该何去何从?
[51Nod1676 无向图同构]无向图哈希[通俗易懂]
Simple use of protobuf
C语言左值和右值说明[通俗易懂]
[JS] the problem pointed by this
性能调试 -- Chrome Performance
磁盘空间的三种分配方式
Uninstall NPM and install NPM_ Use 'NPM uninstall' to uninstall the NPM package 'recommended collection'
The second short contact of gamecloud 1608
这次龙蜥展区玩的新花样,看看是谁的 DNA 动了?
Performance debugging -- chrome performance
C语言:随机生成数+冒泡排序
How to solve the problem of using the download Plug-in for export?
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?
五种分配方式是否会产生内部碎片、外部碎片
JSP初识
立创EDA——器件的创建01-电阻(二)
立创EDA——我为什么要学EDA
How will Web3 change the future of people?
[test development methodology] experience of test development platform PK - choice