Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define a recursive function that finds the result of an arithmetic string. The g

ID: 3935365 • Letter: D

Question

Define a recursive function that finds the result of an arithmetic string. The given string will contain numbers, operators (+, -, *, /), and possibly spaces. You should compute the result respecting order of operations. The function should return an int if the string contains only whole numbers and does not use division. Otherwise, the function should return a float. You do not need to consider division by zero in your solution.

Parameter(s): 1. A string containing numbers, operators (+, -, *, /), and possibly spaces. Return Value: An int or a float of the resulting value.

Example(s): >>> print(solve_eq("1 + 1")) 2

>>> print(solve_eq("1 + 5 * 4")) 21

>>> print(solve_eq("1.0 + 5 * 4")) 21.0

>>> print(solve_eq("1 - 10 * 5 / 80")) 0.375

Explanation / Answer

program :

#include <stdio.h>
int getSum(int x, int y);
int getDifference(int x, int y);
int getProduct(int x, int y);
float getQuotient(int x, int y);
int main()
{
int n1, n2;
int sum, difference, product;
float quotient;
printf("Enter First Number: ");
scanf("%d", &firstNumber);
printf("Enter Second Number: ");
scanf("%d", &secondNumber);
sum = getSum(n1, n2);
difference = getDifference(n1,n2);
product = getProduct(n1,n2);
quotient = getQuotient(n1,n2);
printf(" Sum = %d", sum);
printf(" Difference = %d", difference);
printf(" Multiplication = %d", product);
printf(" Division = %.3f", quotient);
getch();
return 0;
}
int getSum(int x, int y)
{
int sum;
sum = x + y;
return sum;
}
int getDifference(int x, int y)
{
int difference;
difference = x - y;
return difference;
}
int getProduct(int x, int y)
{
int product;
product = x * y;
return product;
}
float getQuotient(int x, int y)
{
float quotient;
quotient = (float)x/y;
return quotient;
}
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote