View Code of Problem 49

#include<stdio.h>
#include <string.h>
#include <math.h>
int main(){
	int n;
	int a[10];
	int i,j;
	int t;
	while(scanf("%d",&n)!=EOF){
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(i=0;i<n-1;i++){
			for(j=0;j<n-1-i;j++){
				if(a[j]>a[j+1]){
					t=a[j];
					a[j]=a[j+1];
					a[j+1]=t;
				}
			}
		}
		for(i=0;i<n;i++){
			if(i==n-1)
			printf("%d",a[i]);
			else
			printf("%d ",a[i]);
		}
		printf("\n");
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 49