当前位置:网站首页>Insert a number into the ordered array (Bubble + rand function)
Insert a number into the ordered array (Bubble + rand function)
2022-04-22 03:59:00 【CTGU tongxuan Shangjing programming hand】
Randomly generated 20 individual 【1,100】 The data of , Order from small to large , Enter a number from the keyboard , Inserting into the ordered array does not change the original sorting rule . use C Written language .
#include <stdio.h>
#include <stdlib.h>
#include <time.h>// Generate header files for random numbers
#define N 20
int main() {
int a[N + 1], i, j, t,temp, posi;//
srand(time(0));// Computers can't produce real random numbers , So you just call rand, Every time something comes out
// It's the same ,Srand Is the number of random seeds planted , You plant different seeds every time , use Rand The random number obtained is different
for (i = 0; i < N; i++)
a[i] = rand() % 101;//rand()%n, It's random 0~(n-1) Number between
for (i = 1; i < N; i++)
for (j = 1; j < N; j++)// First sort with bubbles
if (a[j - 1] > a[j]) {
temp = a[j - 1];
a[j - 1] = a[j];
a[j] = temp;
}
for (i = 0; i < N; i++)
printf("%d ", a[i]);
printf("\n Say it. , What number do you want to enter :");
scanf("%d", &t);
for (i = 0; i < N; i++)
if (t < a[i])
break;
posi = i;// Subscript for the number of inserts
for (i = N - 1; i >= posi; i--)// Move the following numbers one bit back
a[i + 1] = a[i];
a[posi] = t;
for (i = 0; i < N + 1; i++)// Print
printf("%d ", a[i]);
}
Good articles should be more like , Only in this way can more people see !
版权声明
本文为[CTGU tongxuan Shangjing programming hand]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220351433667.html
边栏推荐
- 交通行業提昇數據利用效率的核心是做好數據交換與共享
- The WiFi button of win11 is missing and cannot be connected to the Internet
- Mongodb - $match operation of aggregation pipeline
- MongoDB——聚合管道之$match操作
- Docker starts the general solution of three warnings of redis official image
- 24 pictures to conquer border image
- How do CDN acceleration and CDN defense operate to the server?
- Pycharm jumps to the specified line
- SaaS version goes online, and the applet application ecology goes further
- Wonderful linkage! Principle and practice of openmldb pulsar connector
猜你喜欢

Solution of stm32i2c

export ‘createStore‘ (imported as ‘createStore‘) was not found in ‘./store/index.js‘ (possible expor

DO447Ansible Tower导航

Botu monitor floating-point variable display 16 7fc0_ 0000 exception

偶然间用到的sql语句

Leetcode1615. Maximum network rank (medium)

虚拟dom

Lammps实现结冰匀相成核

How do programmers ensure that software is free of bugs?

vscode 打造 shell 使用
随机推荐
插一个数到排好序的数组中(冒泡+rand函数)
Use of logical backup MySQL dump in MySQL
Detailed explanation of double pointers of ring linked list 1 and 2
Mongodb - $project operation of aggregation pipeline
头歌答案(字符串基本操作)
Deep learning and image recognition: principle and practice notes day_ twelve
Why is Nacos so strong
Lesson 122 of serial 5 of Rasa dialogue robot: the actual operation of Rasa dialogue robot debugging project -- the whole life cycle debugging practice of bank financial dialogue robot - (I)
Deep learning and image recognition: principle and practice notes day_ fifteen
Solve themedata in fluent Primarycolor does not take effect in components such as AppBar
Une solution pour enregistrer l'échec de la connexion à distance MySQL dans la configuration du serveur Cloud
sumo教程——公共交通教程
[golang] force buckle leetcode - 657 Whether the robot can return to the origin (simulation)
Deep learning and image recognition: principle and practice notes day_ seventeen
Set iFLYTEK x Yunnan flying: a tiktok solution to solve the problem of converting passengers to achieve real-time response to private letter reply!
Xiaomi and zhiting's smart cameras protect your family privacy
【树莓派C语言开发】实验12:PCF8591模数转换器模块
Mongodb - $match operation of aggregation pipeline
探究Presto SQL引擎(2)-浅析Join
Length of circular queue "in datastructure"