当前位置:网站首页>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]);
}边栏推荐
- 基于 Docker Compose 的 Nacos(MySQL 持久化)的搭建
- 2022.7.27
- MySQL Soul 16 Questions, How Many Questions Can You Last?
- IDEA 连接 数据库
- 打动中产精英群体,全新红旗H5用产品力跑赢需求
- When Navicat connects to MySQL, it pops up: 1045: Access denied for user 'root'@'localhost'
- 1064 Complete Binary Search Tree
- MySQL联合查询(多表查询)
- Py之pdpbox:pdpbox的简介、安装、案例应用之详细攻略
- #yyds干货盘点# 面试必刷TOP101:判断链表中是否有环
猜你喜欢

It is enough for MySQL to have this article (disgusting typing 37k words, just for Bojun!!!)

MySQL Soul 16 Questions, How Many Questions Can You Last?

ThinkPHP高仿蓝奏云网盘系统源码/对接易支付系统程序

win10重建索引

PhpMetrics 使用

matlab标量场作图

Rust编译报错:error: linker `cc` not found

【MySQL】Mysql事务以及权限管理

mysql跨库关联查询(dblink)

Py's pdpbox: a detailed introduction to pdpbox, installation, and case application
随机推荐
成功解决ImportError: cannot import name ‘_validate_lengths‘
【2022-05-31】JS逆向之易企秀
mysql锁机制
for...in 和 for...of 的区别
The Road to Ad Monetization for Uni-app Mini Program Apps: Rewarded Video Ads
EasyExcel comprehensive course combat
3 minutes to take you to understand WeChat applet development
MySQL 8.0.29 set and modify the default password
MySQL 8.0.29 设置和修改默认密码
MySQL cursors
QT 在父类中添加子类的流程,object tree,
PhpMetrics usage
TCP 连接 三次握手 四次挥手
tcp协议传输中的粘包问题
Go1.18升级功能 - 模糊测试Fuzz 从零开始Go语言
【导航规划】导航规划背景知识总结
WSL2设置默认启动用户(debian)
MySQL user authorization
@RequestBody、 @RequestParam 、 @PathVariable 和 @Vaild 注解
Be careful with your dictionaries and boilerplate code