Files
college-C/3/ex1.c
2022-02-25 15:33:16 +02:00

49 lines
1.3 KiB
C

#include <stdio.h>
#define SUM(a,b) a + b
#define DIFFERENCE(a,b) a - b
#define MULTIPLICATION(a,b) a * b
#define DIVIDE(a,b) a / b
//---------------------------------------------------------------------------------------
// Exercise 1
// ----------
//
// General : The program do math with two numbers and one operator.
//
// Input : 2 numbers (results), 1 char.
//
// Process : The program checks the operator and process math on 2 numbers.
//
// Output : 1 number.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 19.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
float num1,
num2,
result;
char opr;
printf("Enter mathematical expression (a + b): ");
scanf("%f %c %f", &num1, &opr, &num2);
switch (opr)
{
case '-':
result = DIFFERENCE(num1, num2);
break;
case '/':
result = DIVIDE(num1, num2);
break;
case '*':
result = MULTIPLICATION(num1, num2);
break;
default:
result = SUM(num1, num2);
break;
}
printf("The result: %f\n", result);
}