Write a C program to perform simple C arithmetic calculations. The user is to enter a simple expression (integer operator integer) such as
15 + 30
The program is to extract the 2 operands and the operator, perform the indicated calculation and display the result. For example
15 + 30 = 45
Operators should include + , - , * , / , and %
Operands are positive integers , no sign
Use getchar to input the expression
Allow for variable spacing before the first operands and between operators and operands ( 0, 1, or more spaces)

Allow the user the option of entering another expression
Code a function for each operator to do the appropriate arithmetic operations (5 functions)
No global variables
No string handling functions
No arrays
May only use input and output functions such as getchar and putchar

Respuesta :

Answer:

Input example:

select the funcion: 1                                                                                                                  

write the 1sd number2                                                                                                                  

write the 2nd number1                                                                                                                  

value is 2.000000                                                                                                                      

Explanation:

#include <stdio.h>

main()

{

//define the variables as float

float a, b, c, e;

char d;

while (1)  

{      

//input values

printf("select the function: ");

scanf("%c",&d);

printf("write the 1sd number");

scanf("%f",&a);

getchar();

printf("write the 2nd number");

scanf("%f",&b);

getchar();

if (d=='%')

{

    a=a*b/100;

}

if (d=='*')

{

    a=a*b;

}

if (d=='+')

{

    a=a+b;

}

if (d=='/')

{

    a=a/b;

}

if (d=='-')

{

    a=a-b;

}

printf("value is %f \n",a);

}

printf("final value is %f",a);

getchar();

}