当前位置:网站首页>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]);
}
边栏推荐
猜你喜欢
Navicat connection MySQL error: 1045 - Access denied for user 'root'@'localhost' (using password YES)
网安学习-内网渗透3
reindex win10
Go1.18升级功能 - 模糊测试Fuzz 从零开始Go语言
The reason for not using bs4 is that the name is too long?Crawl lottery lottery information
Learning about XML (1)
Go1.18升级功能 - 泛型 从零开始Go语言
【MySQL】DQL相关操作
Abstract classes and interfaces (study notes)
打动中产精英群体,全新红旗H5用产品力跑赢需求
随机推荐
MySQL进阶sql性能分析
A detailed explanation: SRv6 Policy model, calculation and drainage
MySql 5.7.38 download and installation tutorial, and realize the operation of MySql in Navicat
It is enough for MySQL to have this article (disgusting typing 37k words, just for Bojun!!!)
Navicat connection MySQL error: 1045 - Access denied for user 'root'@'localhost' (using password YES)
VS2017 compile Tars test project
MYSQL JDBC Book Management System
Day016 类和对象
连号区间数
Regular expression syntax and usage
Successfully resolved ModuleNotFoundError: No module named 'Image'
OpenCV笔记(二十):滤波函数——filter2D
史上最全的Redis基础+进阶项目实战总结笔记
Collapse legacy apps
The most powerful and most commonly used SQL statements in history
cnpm安装步骤
WSL安装图形界面并通过xrdp/X-Launch访问
MYSQL JDBC图书管理系统
2022.7.28
MySQL 8.0.29 set and modify the default password