Tehtävä 1 Ympyrän halkaisija on 12. Toteuta PHP-koodaus joka laskee ympyrän pintaalan ja kehän mitan käyttäen M_PI:n arvoa.
MATEMAATTISET-FUNKTIOT
PHP-kielen eräs vahvuus on matematiikkaan liittyvät funktiot. Tässä osassa esitellään muutama matemaattinen
funktio ja taulukko-linkeissa joukko muita.
Pii:lle kätevästi likiarvo sijoittamalla rakenteeseen M_PI-arvo.
Esimerkki.
KESKEN käännösten osalta, esimerkit tarkastamatta ja muokkaamatta !!!Pii:lle kätevästi likiarvo sijoittamalla rakenteeseen M_PI-arvo.
Esimerkki.
/* if-lauseen käyttö */ <!DOCTYPE HTML> <html lang="en"> <html> <head> <meta charset="UTF-8"> </head> <body> <?php $Pii = M_PI; echo "Tähän tulostuu Pii:n liki arvo= $Pii"; ?> </body> </html>
Tähän tulostuu Pii:n liki arvo = 3.1415926535898
Taulukossa, PHP:n matemaattiset funktiot ja linkeissä esimerkit.
Funktiot | Tarkoitus | Esimerkki |
---|---|---|
abs() | Returns the absolute (positive) value of a number | Esim |
acos() | Returns the arc cosine of a number | Esim |
acosh() | Returns the inverse hyperbolic cosine of a number | Esim |
asin() | Returns the arc sine of a number | Esim |
asinh() | Returns the inverse hyperbolic sine of a number | Esim |
atan() | Returns the arc tangent of a number in radians | Esim |
atan2() | Returns the arc tangent of two variables x and y | Esim |
atanh() | Returns the inverse hyperbolic tangent of a number | Esim |
base_convert() | Converts a number from one number base to another | Esim |
bindec() | Converts a binary number to a decimal number | Esim |
ceil() | Rounds a number up to the nearest integer | Esim |
cos() | Returns the cosine of a number | Esim |
cosh() | Returns the hyperbolic cosine of a number | Esim |
decbin() | Converts a decimal number to a binary number | Esim |
dechex() | Converts a decimal number to a hexadecimal number | Esim |
decoct() | Converts a decimal number to an octal number | Esim |
deg2rad() | Converts a degree value to a radian value | Esim |
exp() | Calculates the exponent of e | Esim |
expm1() | Returns exp(x) - 1 | Esim |
floor() | Rounds a number down to the nearest integer | Esim |
fmod() | Returns the remainder of x/y | Esim |
getrandmax() | Returns the largest possible value returned by rand() | Esim |
hexdec() | Converts a hexadecimal number to a decimal number | Esim |
hypot() | Calculates the hypotenuse of a right-angle triangl | Esim |
is_finite() | Checks whether a value is finite or not | Esim |
is_infinite() | Checks whether a value is infinite or not | Esim |
is_nan() | Checks whether a value is 'not-a-number' | Esim |
lcg_value() | Returns a pseudo random number in a range between 0 and 1 | Esim |
log() | Returns the natural logarithm of a number | Esim |
log10() | Returns the base-10 logarithm of a number | Esim |
log1p() | Returns log(1+number) | Esim |
max() | Returns the highest value in an array, or the highest value of several specified values | Esim |
min() | Returns the lowest value in an array, or the lowest value of several specified values | Esim |
mt_getrandmax() | Returns the largest possible value returned by mt_rand() | Esim |
mt_rand() | Generates a random integer using Mersenne Twister algorithm | Esim |
mt_srand() | Seeds the Mersenne Twister random number generator | Esim |
octdec() | Converts an octal number to a decimal number | Esim |
pi() | Returns the value of PI | Esim |
pow() | Returns x raised to the power of y | Esim |
rad2deg() | Converts a radian value to a degree value | Esim |
rand() | Generates a random integer | Esim |
round() | Rounds a floating-point number | Esim |
sin() | Returns the sine of a number | Esim |
sinh() | Returns the hyperbolic sine of a number | Esim |
sqrt() | Returns the square root of a number | Esim |
srand() | Seeds the random number generator | Esim |
tan() | Returns the tangent of a number | Esim |
tanh() | Returns the hyperbolic tangent of a number | Esim |