当前位置:网站首页>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;
}
边栏推荐
- Methods of classfile
- Chrome browser tag management plug-in – onetab
- 道阻且长,行则将至
- In depth analysis of how the JVM executes Hello World
- 上班第一天的报错(Nessus安装winpcap报错)
- Error reporting on the first day of work (incomplete awvs unloading)
- Safety production early warning system software - Download safety production app software
- TD联合Modelsim进行功能仿真
- Record personal understanding and experience of game console configuration
- QT signal slot summary -connect function incorrect usage
猜你喜欢
Hystrix implements request consolidation
每天睡前30分钟阅读Day6_Day6_Date_Calendar_LocalDate_TimeStamp_LocalTime
View the port of the application published by was
web安全与防御
图像识别-数据采集
How to install PHP in CentOS
Microservice practice | Eureka registration center and cluster construction
BugkuCTF-web24(解题思路及步骤)
Mysql默认事务隔离级别及行锁
2837xd 代碼生成——StateFlow(4)
随机推荐
Creation and jump of activity
自定義Redis連接池
How to choose between efficiency and correctness of these three implementation methods of distributed locks?
BugkuCTF-web24(解题思路及步骤)
Required request body is missing:(跨域问题)
MySQL error: unblock with mysqladmin flush hosts
Save video opencv:: videowriter
定时线程池实现请求合并
Hystrix implements request consolidation
C语言之分草莓
图像识别-数据增广
PI control of three-phase grid connected inverter - off grid mode
cmake的命令-官方文档
BugkuCTF-web21(详细解题思路及步骤)
2837xd 代码生成——StateFlow(2)
分享一篇博客(水一篇博客)
Is the C language too fat
int与string、int与QString互转
2837xd 代码生成——总结篇
Who is better for Beijing software development? How to find someone to develop system software