当前位置:网站首页>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;
}
边栏推荐
- Don't look for it. All the necessary plug-ins for Chrome browser are here
- Tinyxml2 reading and modifying files
- 逆变器simulink模型——处理器在环测试(PIL)
- MySQL default transaction isolation level and row lock
- Operation and application of stack and queue
- 2837xd 代码生成——StateFlow(3)
- 2837xd 代碼生成——StateFlow(4)
- Pool de connexion redis personnalisé
- Attributes of classfile
- Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
猜你喜欢

2837xd 代码生成——StateFlow(4)

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

TD联合Modelsim进行功能仿真

Fragmenttabhost implements the interface of housing loan calculator

PI control of grid connected inverter (grid connected mode)

分享一篇博客(水一篇博客)

Bold prediction: it will become the core player of 5g

2837xd 代碼生成——StateFlow(4)

Insight into cloud native | microservices and microservice architecture

Chrome browser tag management plug-in – onetab
随机推荐
2837xd 代碼生成——StateFlow(4)
kinect dk 获取CV::Mat格式的彩色RGB图像(openpose中使用)
Error reporting on the first day of work (error reporting when Nessus installs WinPcap)
ClassFile - Attributes - Code
Break the cocoon | one article explains what is the real cloud primordial
Typora installation package sharing
每天睡前30分钟阅读Day5_Map中全部Key值,全部Value值获取方式
JVM instruction mnemonic
Bold prediction: it will become the core player of 5g
Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
Binary and decimal system of C language
Demand delineation executive summary
Chrome video download Plug-in – video downloader for Chrome
Image recognition - Data Cleaning
PI control of three-phase grid connected inverter - off grid mode
Statistical learning methods - Chapter 5, decision tree model and learning (Part 1)
Thinkphp5 how to determine whether a table exists
Alibaba / popular JSON parsing open source project fastjson2
2837xd 代码生成——补充(3)
2837xd 代碼生成——補充(1)