zoukankan      html  css  js  c++  java
  • C语言:10个整数排序(别忘了负数)

    题目内容:

    10个整数排序(别忘了负数)

    例如

    input

    1 0 2 0 3 4 1 9 8 7

    output

    0 0 1 1 2 3 4 7 8 9

    编码:

    void sort(int *a);
    int main()
    {       
    	int i,count=0,a[10];
    	for(i=0; i<10; ++i){
    		scanf("%d",&a[i]);
    		if(a[i]>=0)
    			count++;
    	}
    	sort(a);
    	return 0;
    }
    void sort(int *a){
    	int i,j,temp;
    	for(i=0; i!=9; ++i)
    		for(j=0; j!=9-i; ++j){
    			if(a[j]>a[j+1]){
    				temp=a[j];
    				a[j]=a[j+1];
    				a[j+1]=temp;
    			}
    		}
    		for(i=0; i<10; ++i){
    			printf("%d ",a[i]);
    		}
    

      

  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
  • 原文地址:https://www.cnblogs.com/songqingbo/p/8934319.html
Copyright © 2011-2022 走看看