facebook like button

30 March, 2011

program 22: calculating antilog of a number

The need:
     This is the program to calculate the anti-log of any number to the base 10. This program also introduces you to "double", an important data-type of C.

The code:
-----------------------------------------------
#include <stdio.h>
#include <math.h>
main()
{
    printf("******program to calculate antilog P *******\n\n");
    double i,j;
    printf ("enter the value of P to get its antilog...\n\n\n P= ");
    scanf ("%lf",&i);
    printf("i=%lf\n",i);
    j=pow(10,i);
    printf("antilog P=%lf \n",j);
}
-----------------------------------------------
The approach:
     The program uses the basic fact that anti-log of a number to the base 10 is the value of "10 to the power that number". Here you see a data-type double that is new for you. This data-type is used exactly same as float. It gives you high accuracy and large range in calculations but it uses more memory.

Remarks:
     In previous post I said that math.h functions will be given in this post. Some most commonly used functions are given below:
  1.    sqrt(x): "gives square root of x" or in technical terms we say "returns square root of x"; 
  2.    pow(x,y): returns x raised to the power y;
  3.    exp(x): returns e raised to power x where e is base to natural logarithms;
  4.    log(x): returns natural logarithm of x;
  5.    log10(x): returns log x to base 10;
  6.    sin(x): returns sin(x);
  7.    cos(x): returns cos(x);
  8.    tan(x): returns tan(x);
  9.    asin(x): returns sin-1x;
  10.    acos(x): returns cos-1x;
  11.    atan(x): returns tan-1x;
  12.    ceil10(x): returns smallest integer greater than or equal to x;
  13.    floor10(x): returns greatest integer less than or equal to x;
  14.    fabs10(x): returns absolute value of x;
  15.    fmod(x,y): returns remainder when x is divided by y; This function is needed because '%' operator works only when x and both are int data-type.

  Where x and y are double, and all these functions also return data-type double(wherever I haven't specified). If x and y are not double, C automatically convert them into double, this automatic conversion is called "implicit type conversion".

  Wherever angle is used or returned it's unit is radian not degree.


For details of all functions you can refer links below:
http://www.codingunit.com/category/c-language-reference/c-reference-math-h-functions
http://en.wikipedia.org/wiki/Math.h
http://www.java2s.com/Code/C/math.h/Catalogmath.h.htm 

No comments:

Post a Comment

feel free to ask your doubts... if any
you can post your doubts on
www.facebook.com/programsimply