Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. Consider the following C function :
    float f (float x, int y) {
        float p, s; int i;
    for (s = 1), p = 1, i = 1; i < y; i ++) {
    p* = x/i;
    s + = p;
      }
      return s;
    }
    For large value of y, the return value of the function f best approximates
    1. x y
    2. e x
    3. ln(1+ x)
    4. x x
Correct Option: B

The function is rewritten as Here initial value of s increments every time with a factor of (p)x / i

Thus it can be checked for every value. Here the assumption is that the value of y is very large so y approaches infinity So the series 1+ x + x2 / 2! + x3 / 3!...till infinity will have infinite terms & from our previous knowledge we know that this series is expansion of ex (exponential series) so. 1 + x + x2 / 2! + x3 / 3!...........till infinity = ex
Hence (b) is correct option.



Your comments will be displayed only after manual approval.