What is Function?Types of Function.

=== Library/Built-in/standard Functions ===
A function is a block of statement is a block of that performs a specific task or return single/multiple new/modified
values of a function is as follows:
values to out side. The structure of a function is given below:

function_return_type fun_name ([parameter list]){
Every function must have a useful name.

The parameter list is optional but a pair of parenthesis is must which differentiate
the function name from the variable/named constant.The use of parameters is to
receive/supply value(s) from/to outside.

Function return type may be void (means returns nothing using return st),constant name
or any standard data type(may be int, long, unsigned int/long, char or unsigned char,
float, double, long double), which is the type of the value that the
function returns using return statement.

The body contains single/multiple st(s) under a pair of block markers.

Functions are of two types:
a) built-in/standard/simple type
b) user defined type.
We will study in this class the built-in functions of different classes/categories.

All the built-in types are called value return function that means they return a value
to the calling statement using return statement. This type of function is treated as
a value.You must call/use them as an operand of an other statement/expression.
=== Algebric  functions===

#include <stdio.h>
#include <conio.h>
#include <math.h>//for math functions
void pause(){printf(“\nPress any key to continue..”); getch();}

void ex1(){
/*abs(n) absolute function that returns the absolute value of x, where
x in an int value.
fabs(x)where x is float value */
printf(“\nThe absolute value of an int value -3 is %d”,abs(-3)); //could be a int var/expr
pause();float b=-12.45;
printf(“\nThe value b is %.2f”,b);
printf(“\nThe absolute value of float var b is %.2f”,fabs(b));//error
/*sqrt(x) returns the square root of x, x can never be negative*/
//printf(“\nsquare root of b is %.2f”,sqrt(b));//b can’t be -ve, gives garbage value
printf(“\ncorrect sqrt(b) should be sqrt(fabs(b)) is %.2f”,sqrt(fabs(b)));
/*exp(x) returns the value of e to the power x*/
printf(“\ne to the power 1.0 is %.2f”,exp(1.0));//2.72, do the same for b
/*log(x): Its a natural log*/
printf(“\nlog(10.0) is %.2f”,log(10.0));//ans is 2.30
/*log10(x) : it is ten base log*/
printf(“\nlog10(10.0) is %.2f”,log10(10.0));//ans is 1
/*NOTE: log(n)=2.30*log10(n)==*/
//==floor(x): x rounded down to the nearest integer
float f=2.34;printf(“\nfloor(2.54) is %.f)”, floor(2.54));//2

//==cell(x) x rounded up to the nearest integer
printf(“\nceil(2.53) is %f”,ceil(2.53)); //3
//==pow(x,n) returns the x to the power n
f=pow(2,2.34); printf(“\n2 to the power 2.54 is %f”, pow(2,2.54));
//arguments of pow() are float/double/int

/*==character functions===*/
void ex2(){
/*getch(), getche() returns a character from the keyboard. They don’t need
to press ENTER key while supplying the value from the keyboard. Thery are
call unbuffered function. */
printf(“\nPress any key to continue pl…”);
getch(); //waits to press a character. The character will not echo on the screen.
printf(“\nPress another key to continue pl…”);
getche(); //will the character you press in the keyboard
//In the above we did not preserve/store any where the value you pressed.
//U can use these two functions using another way..
printf(“\nPress a key third times to continue pl…”);
char ch=getch(); printf(“\nThe character u pressed is %c”,ch);
/*getcha(ch) read a character from the keyboard, need to press ENTER after
pressing the character. putchar(ch) display/put the character on the screen. */
printf(“\nGive me a character pl”);
char ch1=getchar(); printf(“\nThe given character is: “);putchar(ch1);

Be the first to comment

Leave a Reply

Your email address will not be published.