1, the n-number of ordered input and output

Subject description:

   The number n of inputs and outputs the result to sort

Input:  

  Comprising a first line of input integer n (1 <= n <= 100), the next line includes n integers

Output:

  From small to large output

Sample input:

4

1 4 3 2

Sample output:

1 2 3 4

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


#include<stdio.h>
#include<algorithm>
using namespace std; 
int main()
{
    int n;
    int buf[1000];
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&buf[i]);
        }
        sort(buf,buf+n);
        for(int i=0;i<n;i++)
        {
            printf("%d ",buf[i]);
        }
        printf("\n");
        return 0;
    }
}

 

Guess you like

Origin www.cnblogs.com/womendouyiyang/p/11665451.html