当前位置:网站首页>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;
}
边栏推荐
- What are the differences between TP5 and laravel
- In SQL injection, why must the ID of union joint query be equal to 0
- kinect dk 获取CV::Mat格式的彩色RGB图像(openpose中使用)
- Image recognition - data annotation
- 自定義Redis連接池
- 因上努力,果上随缘
- In depth analysis of how the JVM executes Hello World
- Chrome user script manager tempermonkey monkey
- 记录下对游戏主机配置的个人理解与心得
- Mysql默认事务隔离级别及行锁
猜你喜欢

2837xd 代码生成——补充(3)

逆变器simulink模型——处理器在环测试(PIL)

2837xd 代码生成——补充(2)

JDBC review

In SQL injection, why must the ID of union joint query be equal to 0

Redis installation and deployment (windows/linux)

MySQL事务

Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd

Typora安装包分享

Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
随机推荐
PI control of grid connected inverter (grid connected mode)
QT signal slot summary -connect function incorrect usage
企业级SaaS CRM实现
图像识别-数据清洗
Typora installation package sharing
TD联合Modelsim进行功能仿真
Share a blog (water blog)
Mysql默认事务隔离级别及行锁
每天睡前30分钟阅读Day5_Map中全部Key值,全部Value值获取方式
Insight into cloud native | microservices and microservice architecture
Binary and decimal system of C language
C语言之做木桶
c语言编程题
Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别
How to use pyqt5 to make a sensitive word detection tool
在SQL注入中,为什么union联合查询,id必须等于0
int与string、int与QString互转
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
MySQL default transaction isolation level and row lock
Mathematics in machine learning -- point estimation (I): basic knowledge