当前位置:网站首页>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;
}
}
}
}
边栏推荐
- I/o case practice
- FAW red flag "King fried" is listed, which is safe and comfortable
- [MAIXPY]kpu: load error:2005, ERR_READ_FILE: read file failed问题解决
- 【饭谈】如何设计好一款测试平台?
- 2022 love analysis ― bank digitalization practice report
- 2022 the latest software tests eight part essay. Whether you can offer depends on how you recite it
- Redisv6.0为何引入多线程?
- Tesseract OCR初探
- [51Nod1676 无向图同构]无向图哈希[通俗易懂]
- Excuse me, how to deal with repeated consumption of MySQL data
猜你喜欢
随机推荐
FAW red flag "King fried" is listed, which is safe and comfortable
3. Editors (vim)
Special class design
Uninstall NPM and install NPM_ Use 'NPM uninstall' to uninstall the NPM package 'recommended collection'
Redis master-slave architecture lock failure problem (master-slave)
动画曲线天天用,你能自己整一个吗?看完这篇你就会了!
【饭谈】测试平台为什么有组件化?模块化?很多看不到的地方设计的很好是种浪费么?
[Fantan] how to design a test platform?
Shopify sellers: share some tips for social media marketing!
2022 the latest software tests eight part essay. Whether you can offer depends on how you recite it
Creation and destruction of function stack frames
卸载npm和安装npm_使用`npm uninstall`卸载npm软件包「建议收藏」
The technical aspects of ByteDance are all over, but the result is still brushed. Ask HR why...
2 lines of code to generate a solid desktop background
I/o case practice
c sqlite ... ...
Guys, how can Flink SQL submit tasks in per job mode?
GPON introduction and Huawei OLT gateway registration and configuration process
[redis underlying parsing] string type
c sqlite ... ...









