码迷,mamicode.com
首页 > 其他好文 > 详细

自定义交换函数

时间:2017-06-06 23:39:27      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:stdio.h   class   clu   scan   print   amp   var   自定义   color   

#include<stdio.h>
#define N 20
 
void Swap(int *temp,int *cont)           /*定义一个交换函数*/
{
    int var;
    var=*temp,*temp=*cont,*cont=var;
    return;
}
 
int main()
{
    int a[N],i,j;
    for(i=0;i<N;i++)
        scanf("%d",&a[i]);
    for(i=1;i<N;i++){
        for(j=0;j<N-i;j++)
            if(a[j]>a[j+1])
                Swap(&a[j],&a[j+1]);    /* 用‘&‘来指向数组中的元素 */
    }
    for(i=0;i<N;i++)
        printf("%d ",a[i]);
    printf("\n");
    return 0;
}

 

自定义交换函数

标签:stdio.h   class   clu   scan   print   amp   var   自定义   color   

原文地址:http://www.cnblogs.com/darkchii/p/6953812.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!