Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //------------------------------------------------------------------------------------------------------------------------------
- // Exercise 3
- // ----------
- // 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.
- //
- // Input : A code and three numbers.
- //
- // Process : The program will check weather the code is 'D' or 'U', and it will arrange the numbers accoring to the code.
- //
- // Output : Sort result.
- //------------------------------------------------------------------------------------------------------------------------------
- // Programmer: Ohad Ozcohen
- // Date: 9.9.2016
- //------------------------------------------------------------------------------------------------------------------------------
- #include <stdio.h>
- #define temp
- #define swap(a,b) (a=a+b , b=a-b , a=a-b);
- void main(void)
- {
- float num1;
- float num2;
- float num3;
- char code;
- printf("Please enter the first number: ");
- scanf_s("%f", &num1);
- printf("Please enter the second number: ");
- scanf_s("%f", &num2);
- printf("Please enter the third number: ");
- scanf_s("%f", &num3);
- fflush(stdin);
- printf("Please enter a code: ");
- scanf_s("%c", &code);
- if (num1 > num3)
- {
- swap(num1, num3);
- }
- if (num1 > num2)
- {
- swap(num1, num2);
- }
- if (num2 > num3)
- {
- swap(num2, num3);
- }
- if (code == 'D')
- {
- swap(num1, num3);
- }
- printf("%f %f %f", num1, num2, num3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement