0% found this document useful (0 votes)
10K views3 pages

The SQRT Function

The document summarizes several math functions from the cmath header file including sqrt(), pow(), fabs(), ceil(), floor(), cos(), tan(), sin(), log(), and log10(). It also describes functions from the cctype header file such as tolower() and toupper() for case conversion. Finally, it discusses the cstdlib functions rand() for generating pseudorandom numbers and srand() for seeding the random number generator used by rand().

Uploaded by

Ysabelle Jimenea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10K views3 pages

The SQRT Function

The document summarizes several math functions from the cmath header file including sqrt(), pow(), fabs(), ceil(), floor(), cos(), tan(), sin(), log(), and log10(). It also describes functions from the cctype header file such as tolower() and toupper() for case conversion. Finally, it discusses the cstdlib functions rand() for generating pseudorandom numbers and srand() for seeding the random number generator used by rand().

Uploaded by

Ysabelle Jimenea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Ysabelle Therese Jimenea ENCH5B

Computer Applications

The sqrt() function

Source code:
#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;

int main()
{
double param, result;

param=123.45;
result=sqrt(param);
cout<<"sqrt("<<param<<") = "<<result<<endl;

getch();
return 0;
}

Screen output:

The pow() function

Source code:
#include <iostream>
#include <cmath>
using namespace std;

int main()

{
double resultx,resulty;

resultx=pow(5,3);
cout<<"5 raised to the power of 3 is "<<resultx<<endl;
resulty=pow(3,4);
cout<<"3 raised to the power of 4 is "<<resulty<<endl;

return 0;
}

Screen output:

Description and syntax

cmath functions:

1. fabs - returns the absolute value of the argument.


2. ceil - returns the smallest possible integer value which is greater than or equal to the
given argument.
3. floor - the largest possible integer value which is less than or equal to the given
argument.
4. cos - returns the cosine of an angle (argument) given in radian.
5. tan - returns the tangent of an angle (argument) given in radian.
6. sin - returns the sine of an angle (argument) given in radian.
7. log – returns the natural logarithm of x: the inverse of the natural exponential function.
8. log10 - returns the common (base-10) logarithm of x.

cctype functions

1. tolower - The tolower() function converts ch to its lowercase version if it exists. If the
lowercase version of a character does not exist, it remains unmodified. The uppercase
letters from A to Z is converted to lowercase letters from a to z respectively. The
behaviour of tolower() is undefined if the value of ch is not representable as unsigned
char or is not equal to EOF. It is defined in <cctype> header file.
2. toupper - The toupper() function converts ch to its uppercase version if it exists. If the
uppercase version of a character does not exist, it remains unmodified. The lowercase
letters from a to z is converted to uppercase letters from A to Z respectively. The
behaviour of toupper() is undefined if the value of ch is not representable as unsigned
char or is not equal to EOF. It is defined in <cctype> header file.

cstdlib functions

1. rand - One way to generate these numbers in C++ is to use the function rand(). Rand is
defined as: #include <cstdlib> int rand(); ... It is a number that is not truly random, but
appears random. That is, every number between 0 and RAND_MAX has an equal chance
(or probability) of being chosen each time rand() is called.
2. srand -The srand() function in C++ seeds the pseudo random number generator used by
the rand() function. The seed for rand() function is 1 by default.
It means that if no srand() is called before rand(), the rand() function behaves as if it was
seeded with srand(1).

You might also like