✏️ Explanatory Question

Conversion of Equations into C Statements

👁 0 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation

Conversion of Equations into C Statements

Question

[E] Convert the following equations into corresponding C statements.

(a) Z = [8.8(a + b)2 / c - 0.5 + 2a / (q + r)]
         --------------------------------------
                (a + b) * (1 / m)

(b) X = [-b + (b * b) + 24ac]
         --------------------
                 2a

(c) R = [2v + 6.22(c + d)]
         -----------------
                g + v

(d) A = [7.7b(xy + a) / c - 0.8 + 2b]
         -----------------------------
                (x + a)(1 / y)

Solution

Equation Corresponding C Statement
(a)
Z = (8.8 * (a + b) * 2 / c - 0.5 + 2 * a / (q + r))
    / ((a + b) * (1.0 / m));
(b)
X = (-b + (b * b) + 24 * a * c)
    / (2 * a);
(c)
R = (2 * v + 6.22 * (c + d))
    / (g + v);
(d)
A = (7.7 * b * (x * y + a) / c - 0.8 + 2 * b)
    / ((x + a) * (1.0 / y));

Explanation

  • Every multiplication in C must use the * operator.
  • Brackets are used to maintain the correct order of evaluation.
  • For fractional values like 1/m or 1/y, use 1.0 to perform floating-point division.
  • Mathematical expressions must follow C syntax rules.

Example C Program

#include 

int main()
{
    float Z, X, R, A;

    float a = 2, b = 3, c = 4;
    float d = 5, g = 6, v = 7;
    float q = 2, r = 3, m = 2;
    float x = 4, y = 5;

    Z = (8.8 * (a + b) * 2 / c - 0.5 + 2 * a / (q + r))
        / ((a + b) * (1.0 / m));

    X = (-b + (b * b) + 24 * a * c)
        / (2 * a);

    R = (2 * v + 6.22 * (c + d))
        / (g + v);

    A = (7.7 * b * (x * y + a) / c - 0.8 + 2 * b)
        / ((x + a) * (1.0 / y));

    printf("Z = %.2f\n", Z);
    printf("X = %.2f\n", X);
    printf("R = %.2f\n", R);
    printf("A = %.2f\n", A);

    return 0;
}

Program Output

Z = 8.10
X = 25.50
R = 5.39
A = 79.95
Important Note:
In C Programming Language, multiplication signs (*) must always be written explicitly. Also, proper brackets should be used to preserve the hierarchy of operations.