Tuesday 19 January 2016

Library Mathematical and Date functions in C Language

Library Mathematical Functions
Following are the functions defined in the header math.h −
S.N.
Function & Description
1
Returns the arc cosine of x in radians.
2
Returns the arc sine of x in radians.
3
Returns the arc tangent of x in radians.
4
Returns the arc tangent in radians of y/x based on the signs of both values to determine the correct quadrant.
5
Returns the cosine of a radian angle x.
6
Returns the hyperbolic cosine of x.
7
Returns the sine of a radian angle x.
8
Returns the hyperbolic sine of x.
9
Returns the hyperbolic tangent of x.
10
Returns the value of e raised to the xth power.
11
The returned value is the mantissa and the integer pointed to by exponent is the exponent. The resultant value is x = mantissa * 2 ^ exponent.
12
Returns x multiplied by 2 raised to the power of exponent.
13
Returns the natural logarithm (base-e logarithm) of x.
14
Returns the common logarithm (base-10 logarithm) ofx.
15
The returned value is the fraction component (part after the decimal), and sets integer to the integer component.
16
Returns x raised to the power of y.
17
Returns the square root of x.
18
Returns the smallest integer value greater than or equal to x.
19
Returns the absolute value of x.
20
Returns the largest integer value less than or equal to x.
21
Returns the remainder of x divided by y.

Date and Time functions in C
  Time functions in C are used to interact with system time routine and formatted time outputs are displayed. Example programs for the time functions are given below.
S.no
Function
Description
1
setdate()
This function used to modify the system date
2
getdate()
This function is used to get the CPU time
3
clock()
This function is used to get current system time
4
time()
This function is used to get current system time as structure
5
difftime()
This function is used to get the difference between two given times
6
strftime()
This function is used to modify the actual time format
7
mktime()
This function interprets tm structure as calendar time
8
localtime()
This function shares the tm structure that contains date and time informations
9
gmtime()
This function shares the tm structure that contains date and time informations
10
ctime()
This function is used to return string that contains date and time informations
11
asctime()
Tm structure contents are interpreted by this function as calendar time. This time is converted into string.

Example program for setdate() function in C:

This function is used to modify the system date. Please note that other C compilers may not support this setdate() function except turbo C.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<stdio.h>
#include<dos.h>
#include<conio.h>
int main()
{
   struct date dt;

   printf("Enter new date in the format(day month year)");
   scanf("%d%d%d",&dt.da_day,&dt.da_mon,&dt.da_year);

   setdate(&dt);

   printf("Now, current system date is %d-%d-%d\n",dt.da_day,dt.da_mon,dt.da_year);
   return 0;
  }

  

Output:

Enter new date in the format (day month year)
01 12 2012
Now, current system date is 01-12-2012

Example program for getdate() function in C:

This function is used to get the CPU time. Please note that other C compilers may not support this getdate() function except turbo C.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include<stdio.h>
#include<dos.h>
int main()
{
   struct date dt;

   getdate(&dt);

   printf("Operating system's current date is %d-%d-%d\n"
   ,dt.da_day,dt.da_mon,dt.da_year);

   return 0;
}

Output:

Operating system’s current date is 12-01-2012


No comments:

Post a Comment