当前位置:网站首页>Minimum number of C language
Minimum number of C language
2022-07-02 09:44:00 【FF small confused acridine~】
Keyboard entry N(N ≤ 20) individual 0-9 Numbers , You can arrange these numbers in any order , But all must be used . The goal is to make the final number as small as possible ( Be careful 0 Can't be the first ).
for example :
Given two 0, Two 1, Three 5, One 8, The smallest number we get is 10015558.
Programming requirements :
1、N The value of :N ≤ 20;
2、 The entered number contains at least one non-zero number ;
3、 Please use 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 the number of numbers N:6
Please enter 6 A digital :0 1 7 2 0 3
The minimum number of components is :100237
Please press any key to continue . . .
Running effect 2:
Please enter the number of numbers N:8
Please enter 8 A digital :0 1 5 5 8 1 0 5
The minimum number of components is :10015558
Please press any key to continue . . .
#include <stdio.h>
int main(void)
{
int N ,arr[20] ,i ,j ,temp;
printf(" Please enter the number of numbers N:");
scanf("%d" ,&N);
printf(" Please enter %d A digital :", N);
for (i = 0; i < N; i++)
scanf("%d" ,&arr[i]);
for (i = 0; i < N - 1; i++)
for(j = 0; j < N - i -1 ; ++j)
{
if(arr[j] > arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
for (i = 0; i < N; i++)
if(arr[i] != 0)
{
temp = arr[i];
arr[i] = arr[0];
arr[0] = temp;
break;
}
printf(" The minimum number of components is :" );
for (i = 0; i < N; i++)
printf("%d" ,arr[i]);
printf("\n");
return 0;
}
#include <stdio.h>
int main(void)
{
int a[21];
int n,i,j,m;
printf(" Please enter the number of numbers N: ");
scanf("%d",&n);
printf(" Please enter %d A digital : ",n);
for(i=0;i<n;++i){
scanf("%d",&a[i]);
}
for(i=0;i<n-1;++i){
for(j=0;j<n-1;++j){
if(a[j]>a[j+1]){
m=a[j];
a[j]=a[j+1];
a[j+1]=m;
}
}
}
for(i=0;a[i]==0;++i);
m=a[i];
a[i]=a[0];
a[0]=m;
printf(" The smallest number of components is : ");
for(i=0;i<n;++i){
printf("%d",a[i]);
}
printf("\n");
return 0;
}
边栏推荐
- How to use pyqt5 to make a sensitive word detection tool
- 每天睡前30分钟阅读Day6_Day6_Date_Calendar_LocalDate_TimeStamp_LocalTime
- TD联合Modelsim进行功能仿真
- Discussion on improving development quality and reducing test bug rate
- 2837xd 代码生成——StateFlow(1)
- vs+qt 设置应用程序图标
- C language programming problems
- Thinkphp5 how to determine whether a table exists
- kinect dk 获取CV::Mat格式的彩色RGB图像(openpose中使用)
- Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
猜你喜欢
TD联合Modelsim进行功能仿真
Hystrix implements request consolidation
QT qlabel style settings
tinyxml2 读取和修改文件
Image recognition - data augmentation
Record the interesting process of using Xray for the first time
Navicat 远程连接Mysql报错1045 - Access denied for user ‘root‘@‘222.173.220.236‘ (using password: YES)
自定義Redis連接池
Image recognition - Data Acquisition
Insight into cloud native | microservices and microservice architecture
随机推荐
Required request body is missing:(跨域问题)
Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别
How to use PHP spoole to implement millisecond scheduled tasks
Read Day5 30 minutes before going to bed every day_ All key values in the map, how to obtain all value values
College Students' CET-4 and CET-6 composition template (self created version, successfully crossed CET-6)
个人经历&&博客现状
Kinect DK obtains color RGB images in cv:: mat format (used in openpose)
保存视频 opencv::VideoWriter
图像识别-数据增广
Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
cmake的命令-官方文档
每天睡前30分钟阅读Day6_Day6_Date_Calendar_LocalDate_TimeStamp_LocalTime
2837xd Code Generation - Supplement (1)
Microservice practice | Eureka registration center and cluster construction
Chrome video download Plug-in – video downloader for Chrome
2837xd 代码生成——补充(3)
vs+qt 设置应用程序图标
In depth analysis of how the JVM executes Hello World
BugkuCTF-web24(解题思路及步骤)
Demand delineation executive summary