Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //------------------------------------------------------------------------------------------------------------------------------
- // Exercise 1
- // ----------
- //
- // General : The program will get two numbers and a mathematical operator, and it will solve the equation.
- //
- // Input : Two numbers and a numeric operator.
- //
- // Process : The program performs the operation requested on the two numbers.
- //
- // Output : Prints the equation and its sulotion.
- //
- //------------------------------------------------------------------------------------------------------------------------------
- // Programmer: Ohad Ozcohen
- // Date: 9.9.2016
- //------------------------------------------------------------------------------------------------------------------------------
- #include <stdio.h>
- void main(void)
- {
- float num1;
- float num2;
- char operator='+';
- printf("Please enter the first number: ");
- scanf_s("%f", &num1);
- printf("Please enter the second number: ");
- scanf_s("%f", &num2);
- float result= num1+num2;
- printf("Please an operator: ");
- fflush(stdin);
- scanf_s("%c", &operator);
- if (operator=='-')
- {
- result = num1-num2;
- }
- if (operator=='/')
- {
- result = num1/num2;
- }
- if (operator=='*')
- {
- result = num1*num2;
- }
- printf("\n%.2f %c %.2f = %.2f", num1, operator, num2, result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement