First Upload
This commit is contained in:
49
3/ex1.c
Normal file
49
3/ex1.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user