Blue Bridge Cup C language basic training sequence sorting, blue bridge basic training

Source: Internet
Author: User

Blue Bridge Cup C language basic training sequence sorting, blue bridge basic training
The Problem description is given a series with a length of n, which is arranged in ascending order. 1 <= n <= 200 the first row of the input format is an integer n.
The second row contains n integers, which are the numbers to be sorted. The absolute value of each integer is less than 10000. The output format outputs a row, and the sorted series are output in ascending order. Sample input 5
8 3 6 4 9 sample output 3 4 6 8 9

#include<stdio.h>

int main(){
	int n,i,j,t,z=1;
	scanf("%d",&n);
	int a[n];
	for( i=0;i<n;i++)
		scanf("%d",&a[i]);
	for( i=0;i<n;i++){
	
		for(j=i+1;z<=n-i-1;j++,z++){
			if(a[i]>a[j]){
				t=a[i];
				a[i]=a[j];
				a[j]=t;
				
			}
		
			
		}
		z=1;
	}
	for( i=0;i<n;i++)
		printf("%d ",a[i]);
	printf("\n");
	return 0;
}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.