iForeRunner
 
   
 
  c  
   
   
   
 
  RECUSIONS  
 
 



Recursive Functions in 'C' language


Recursive Functions:- A function is called 'Recursive' if a statement within the body of a function calls the same function. This is also called as 'Circular definition'.

Eg:
main(){
    long int fact, n, factorial(long int); clrscr();
    printf("\nEnter a number :");
    scanf("%ld",&n);
    fact=factorial(n);
    printf("\nThe factorial of a given number is %ld",fact);
    getch();
}

long int factorial (long int p) {
    long int fac=1;
    if(fac==1)
     return 1;
    else
     return (p*factorial(p-1));
}

Passing Arrays To The Function:- We can pass single dimensional & double dimensional arrays as parameters to a function. There is no need of returning an array from the function to the calling program. This is because whatever changes we make in the formal parameter array, they will get reflected in the actual parameter array.

Eg:
main()
{
    int a[10],n, i, display(int [], int);
    clrscr();
    printf("\nEnter the number of elements :");
    scanf("%d",&n);
    printf("\nEnter the values :");
    for(i=0;i     scanf("%d",&a[i]);
    printf("\nThe values accepted are :");
    display(a,n);
    getch();
}

display(int p[10], int m){
    int i;
    for(i=0;i     printf("\n%d",p[i]);
}

DIFFERENT DATATYPES AVAILABLE IN C : The datatypes in C are categorized into four types.

1. Primary datatype eg: int, float, char etc.,
2. User defined datatype eg: typedef, enum
3. Derived datatype eg: structure, union
4. Empty dataset eg: void


Please send comments to vgdarur.javafive@blogger.com