当前位置:网站首页>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;
}
边栏推荐
- 2837xd 代码生成——StateFlow(4)
- 2837xd 代碼生成——補充(1)
- Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
- Microservice practice | Eureka registration center and cluster construction
- 一次聊天勾起的回忆
- 2837xd code generation - Summary
- Say goodbye to 996. What are the necessary plug-ins in idea?
- Required request body is missing: (cross domain problem)
- 企业级SaaS CRM实现
- Image recognition - Data Cleaning
猜你喜欢

在SQL注入中,为什么union联合查询,id必须等于0

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

Navicat remote connection MySQL reports an error 1045 - access denied for user 'root' @ '222.173.220.236' (using password: yes)

自定義Redis連接池

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

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

Tinyxml2 reading and modifying files

Personal experience & blog status

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

MySQL multi column in operation
随机推荐
idea查看字节码配置
2837xd 代碼生成——StateFlow(4)
How to install PHP in CentOS
DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!
int与string、int与QString互转
Cmake command - Official Document
并网逆变器PI控制(并网模式)
图像识别-数据清洗
Error reporting on the first day of work (incomplete awvs unloading)
Idea view bytecode configuration
Inverter Simulink model -- processor in the loop test (PIL)
Personal experience & blog status
Timed thread pool implements request merging
Pool de connexion redis personnalisé
TD conducts functional simulation with Modelsim
Image recognition - Data Acquisition
FragmentTabHost实现房贷计算器界面
Statistical learning methods - Chapter 5, decision tree model and learning (Part 1)
Is the C language too fat
Image recognition - Data Cleaning