当前位置:网站首页>Data insertion in C language
Data insertion in C language
2022-07-02 09:44:00 【FF small confused acridine~】
Programming , Input from keyboard 8 A non decreasing ordered sequence of numbers and put it into a one-dimensional array , Enter another number elem, And put this number elem Insert into the array , And still maintain non decreasing order , If the inserted number is larger than all the original numbers, it will be placed at the end , Than the original number of hours on the front .
Programming requirements :
1、 The data in the series are all integers ;
2、 Non decreasing order : That is, from small to large, or allow equal situations in the middle , such as 1 3 4 5 5 6 That is, non decreasing order ;
3、 Please use the method of array to realize ;
4、 Please output strictly according to the output effect ;( Affect the performance evaluation )
5、 When submitting the code of the task, it is necessary to ensure that it conforms to the industry code specification , You need to indent and wrap as necessary .( Affect the performance evaluation )
Running effect 1:
Please enter in non decreasing order 8 It's an integer :
2 3 3 10 15 16 28 30
Please enter elem:3
Insert elem The result is :
2 3 3 3 10 15 16 28 30
Please press any key to continue . . .
Running effect 2:
Please enter in non decreasing order 8 It's an integer :
3 4 10 15 16 66 78 80
Please enter elem:81
Insert elem The result is :
3 4 10 15 16 66 78 80 81
Please press any key to continue . . .
Running effect 3:
Please enter in non decreasing order 8 It's an integer :
11 22 33 45 56 57 77 89
Please enter elem:3
Insert elem The result is :
3 11 22 33 45 56 57 77 89
Please press any key to continue . . .
#include <stdio.h>
int main(void)
{
int n ,arr[9] ,i ,elem ,j;
printf(" Please enter in non decreasing order 8 It's an integer :\n");
for (i = 0; i < 8; i++)
scanf("%d" ,&arr[i]);
printf(" Please enter elem:");
scanf("%d" ,&elem);
for (i = 0; i < 8; i++)
if(arr[i] > elem)
break;
for (j = 7; j >= i; j--)
arr[j+1] = arr[j];
arr[i] = elem;
printf(" Insert elem The result is :\n");
for (i = 0; i <= 8; i++)
printf("%d " ,arr[i]);
printf("\n");
return 0;
}
#include <stdio.h>
int main(void)
{
int arr[9],elem;
int a,b,j;
printf(" Please enter in non decreasing order 8 It's an integer :\n");
for(a=0;a<8;++a)
{
scanf("%d",&arr[a]);
}
printf(" Please enter elem:");
scanf("%d",&elem);
printf(" Insert elem The result is :\n");
arr[8]=elem;
for(a=0;a<8;++a){
for(j=0;j<8-a;++j){
if(arr[j]>arr[j+1]){
b=arr[j];
arr[j]=arr[j+1];
arr[j+1]=b;
}
}
}
for(a=0;a<9;++a){
printf("%d ",arr[a]);
}
printf("\n");
return 0;
}
边栏推荐
猜你喜欢
Timed thread pool implements request merging
zk配置中心---Config Toolkit配置与使用
Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
保存视频 opencv::VideoWriter
QT qlabel style settings
定时线程池实现请求合并
Chrome browser plug-in fatkun installation and introduction
Chrome video download Plug-in – video downloader for Chrome
2837xd代码生成模块学习(4)——idle_task、Simulink Coder
Memories of a chat
随机推荐
Mysql默认事务隔离级别及行锁
Off grid control of three-phase inverter - PR control
MySQL error: unblock with mysqladmin flush hosts
Required request body is missing: (cross domain problem)
Microservice practice | Eureka registration center and cluster construction
2837xd code generation - Summary
Idempotent design of Internet API interface
Image recognition - data annotation
ClassFile - Attributes - Code
MySql报错:unblock with mysqladmin flush-hosts
自定義Redis連接池
个人经历&&博客现状
Bugkuctf-web21 (detailed problem solving ideas and steps)
Methods of classfile
保存视频 opencv::VideoWriter
zk配置中心---Config Toolkit配置与使用
vs+qt 设置应用程序图标
Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
Record personal understanding and experience of game console configuration
图像识别-数据采集