首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

C语言逆序排列三个数

2012-10-28 
C语言逆序排列3个数/* ----------------------------------------- Copyright (c) 2010-2011 Zidane LiUsa

C语言逆序排列3个数

/* ----------------------------------------- Copyright (c) 2010-2011 Zidane Li  Usage of this program is free for non-commercial use. ----------------------------------------- *//*    1.16自大至小依次输出顺序读入的三个整数*/#include <stdio.h>#include <stdlib.h>void Swap(int* a, int* b){    int* temp = (int*)malloc(sizeof(int));    *temp = *a;    *a = *b;    *b = *temp;free(temp);}void CompareThreeNumbers(int* a, int* b, int* c){    //将a和b排序    if (*a < *b)      {        Swap(a, b);    }    //根据c在a和b的范围,排列a、b、c    if (*b < *c)    {        Swap(c, b);if (*a < *b)    {        Swap(b, a);    }    }}int main(){    printf("Input 3 numbers, I'll sort them ACS: ");    int a, b, c;    scanf("%i%i%i", &a, &b, &c);    CompareThreeNumbers(&a, &b, &c);    printf("%i %i %i\n", a, b, c);    return 0;}
?

热点排行