C++


  FUNCTIONS

A function is a locked sequence of instructions that allows multiple use with different parameters. A function is a sub-programme.
The function is declared in the following way

   type_of_result function_name (parametrs) {instructions}

Example:

   float change(float tempF)
   {
   float tempC; tempC=((tempF-32)*5)/9;
   return tempC;
   }
   main()
   {
   float tF, tC;
   cout<<”Enter the Fahrenheit degree temperature:”;
   cin>>tF;
   tC=change(tF);
   cout<<”Temperature in degrees Celsius=”<<tC;
   return 0;
   }


  RECURRING FUNCTIONS

Recurring functions are functions that call themselves.
Examples:

 long int fact (int n)
   {
   if (n == 0) return 1;
   return fact(n-1)*n;
   }


 int Euklid (int a, int b)
   {
   if (a==b) return a;
   else if (a>b) return Euklid(a-b, b);
   else return Euklid(a, b-a);
   }


 int Fibon (int n)
   {
   if (n==1 || n==2) return 1;
   else return Fibon(n-2)+Fibon(n-1);
   }