sort3.c - OpenLearning
// Description: Sorts 3 numbers and prints them out in ascending order
// Activity Section: 2. Memory, Types, Functions
// Date: 13/3/15
// by Sabrina Rispin
//---------------------------72-characters------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

void orderNum (int a, int b, int c);
void printSecondNum (int a, int b);

int main (int argc, char * argv[]) {
   int first, second, third;
   scanf ("%d %d %d", &first, &second, &third);

   orderNum(first, second, third);

   return EXIT_SUCCESS;
}

void orderNum (int a, int b, int c) {
   assert ((a != b) && (a != c) && (b != c));

   if ((a < b) && (a < c)) {
      printf ("%d\n", a);
      printSecondNum (b, c);
   } else if ((b < a) && (b < c)) {
      printf ("%d\n", b);
      printSecondNum (a, c);
   } else {
      printf ("%d\n", c);
      printSecondNum (a, b);
   }
}

void printSecondNum (int a, int b) {
   if (a < b) {
      printf ("%d\n", a);
      printf ("%d\n", b);
   } else {
      printf ("%d\n", b);
      printf ("%d\n", a);
   }
}

Download file: sort3.c (1.0 KB)

Comments

Chat