# Untitled

Sep 8th, 2016
1,165
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. //------------------------------------------------------------------------------------------------------------------------------
2. //                                                                  Exercise 3
3. //                                                                  ----------
4. // General : The program will get three numbers and and a code. If the code is 'U', the program will arrange the numbers from small to big. If the code is 'D', the program will arrange the numbers from big to small.
5. //
6. // Input   : A code and three numbers.
7. //
8. // Process : The program will check weather the code is 'D' or 'U', and it will arrange the numbers accoring to the code.
9. //
10. // Output  : Sort result.
11. //------------------------------------------------------------------------------------------------------------------------------
13. // Date: 9.9.2016
14. //------------------------------------------------------------------------------------------------------------------------------
15. #include <stdio.h>
16. #define temp
17. #define swap(a,b)  (a=a+b , b=a-b , a=a-b);
18. void main(void)
19. {
20.     float num1;
21.     float num2;
22.     float num3;
23.     char code;
24.     printf("Please enter the first number: ");
25.     scanf_s("%f", &num1);
26.     printf("Please enter the second number: ");
27.     scanf_s("%f", &num2);
28.     printf("Please enter the third number: ");
29.     scanf_s("%f", &num3);
30.     fflush(stdin);
31.     printf("Please enter a code: ");
32.     scanf_s("%c", &code);
33.
34.     if (num1 > num3)
35.     {
36.         swap(num1, num3);
37.     }
38.
39.     if (num1 > num2)
40.     {
41.         swap(num1, num2);
42.     }
43.     if (num2 > num3)
44.     {
45.         swap(num2, num3);
46.     }
47.     if (code == 'D')
48.     {
49.         swap(num1, num3);
50.     }
51.     printf("%f %f %f", num1, num2, num3);
52. }