Advertisement
ohad

Untitled

Sep 8th, 2016
2,710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //------------------------------------------------------------------------------------------------------------------------------
  2. //                                                                  Exercise 1
  3. //                                                                  ----------
  4. //
  5. // General : The program will get two numbers and a mathematical operator, and it will solve the equation.
  6. //
  7. // Input   : Two numbers and a numeric operator.
  8. //
  9. // Process : The program performs the operation requested on the two numbers.
  10. //
  11. // Output  : Prints the equation and its sulotion.
  12. //
  13. //------------------------------------------------------------------------------------------------------------------------------
  14. // Programmer: Ohad Ozcohen
  15. // Date: 9.9.2016
  16. //------------------------------------------------------------------------------------------------------------------------------
  17. #include <stdio.h>
  18. void main(void)
  19. {
  20.     float num1;
  21.     float num2;
  22.     char operator='+';
  23.     printf("Please enter the first number: ");
  24.     scanf_s("%f", &num1);
  25.     printf("Please enter the second number: ");
  26.     scanf_s("%f", &num2);
  27.     float result= num1+num2;
  28.     printf("Please an operator: ");
  29.     fflush(stdin);
  30.     scanf_s("%c", &operator);
  31.     if (operator=='-')
  32.     {
  33.         result = num1-num2;
  34.     }
  35.     if (operator=='/')
  36.     {
  37.         result = num1/num2;
  38.     }
  39.     if (operator=='*')
  40.     {
  41.         result = num1*num2;
  42.     }
  43.     printf("\n%.2f %c %.2f = %.2f", num1, operator, num2, result);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement