This blog is under construction

Monday, 30 April 2012

ldexp example in C

Header file:
    math.h

Synopsis:
     double ldexp(double x, int exp);

Description:
     Returns the value of x multiplied by 2 to the power of exp.


ldexp function C example:


  #include<stdio.h>
  #include<math.h>
  int main() {
        double x, res;
        int n;
        printf("Enter the value of x and n:");
        scanf("%lf%d", &x, &n);
        res = ldexp(x, n);
        printf("%lf * 2 ^ %d = %lf\n", x, n, res);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/cpgms/math$ ./a.out
  Enter the value of x and n:2 4
  2.000000 * 2 ^ 4 = 32.000000


No comments:

Post a Comment