当前位置:网站首页>ZZULIOJ:1119: 数列有序
ZZULIOJ:1119: 数列有序
2022-07-30 22:46:00 【追上】
1119: 一维数组排序
时间限制: 1 Sec 内存限制: 128 MB
[状态] [讨论版] [提交] [命题人:admin]
题目描述
对一维数组按照从小到大的顺序排序。程序定义函数sort()来实现数组a的排序。函数原型如下:
void sort(int a[], int n);
数组元素的输出调用PrintArr()。
输入
第一行输入一个整数n(1<=n<=10),表示数组有n个整数;第二行输入n个整数。
输出
输出占一行。对这n个整数数按照从小到大的顺序输出,数据之间用一个空格隔开。
样例输入 Copy
6 6 5 1 2 3 4
样例输出 Copy
1 2 3 4 5 6
参考代码
#include <stdio.h>
#include <stdlib.h>
#define N 10
void sort(int a[],int n);
void PrintArr(int a[], int n);
int main()
{
int a[N];
int n, i;
scanf("%d", &n);
for(i=0;i<n;i++)
{
scanf("%d", &a[i]);
}
sort(a, n);
PrintArr(a, n);
return 0;
}
void sort(int a[], int n)
{
int i, j, t;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[j];
a[j]=a[i];
a[i]=t;
}
}
}
}
void PrintArr(int a[], int n)
{
int i;
for(i=0;i<n;i++)
printf("%d ", a[i]);
}
边栏推荐
- Go语学习笔记 - gorm使用 - 表增删改查 Web框架Gin(八)
- Mysql进阶优化篇01——四万字详解数据库性能分析工具(深入、全面、详细,收藏备用)
- 2022/07/30 学习笔记 (day20) 面试题积累
- Gxlcms有声小说系统/小说听书系统源码
- Navicat new database
- 【微信小程序】小程序突破小程序二维码数量限制
- MySQL 8.0.29 解压版安装教程(亲测有效)
- The reason for not using bs4 is that the name is too long?Crawl lottery lottery information
- Solve the problem of centos8 MySQL password ERROR 1820 (HY000) You must reset your password using the ALTER USER
- Detailed operator
猜你喜欢
随机推荐
只会纯硬件,让我有点慌
tcp协议传输中的粘包问题
力扣题(2)—— 两数相加
482-静态库、动态库的制作、使用及区别
Successfully solved ImportError: always import the name '_validate_lengths'
MySQL user authorization
【MySQL】MySQL中对数据库及表的相关操作
设备树的引入与体验
Golang go-redis cluster模式下不断创建新连接,效率下降问题解决
代码越写越乱?那是因为你没用责任链
cnpm安装步骤
OpenCV笔记(二十):滤波函数——filter2D
1064 Complete Binary Search Tree
CISP-PTE Zhenti Demonstration
ClickHouse to create a database to create a table view dictionary SQL
IJCAI2022教程 | 口语语言理解:最新进展和新领域
A detailed explanation: SRv6 Policy model, calculation and drainage
史上超强最常用SQL语句大全
DistSQL in-depth analysis: creating a dynamic distributed database
mysql锁机制