Appendix

C PROGRAMMING FOR SOME ALGORITHMS

  1. To write a recursive function to print the factorial of a number and execute it to find the factorial of 6.

    #include <stdio.h>

    #include <conio.h>

    unsigned long fact(int);

    void main()

    {

    unsigned long f;

    int n;

    clrscr();

    printf(“\nEnter a number: “);

    scanf(“%d”,&n);

    f=fact(n);

    printf(“\nFactorial of %d is %ld”,n,f);

    getch();

    }

    unsigned long fact(int n)

    {

    unsigned long m;

    if(n==1)

        return(1);

    else

        m=n*fact(n−1);

    return(m);

    }

    The Execution of the program to find the factorial of 6 is yields:-

    Enter a Number:

    6

    Factorial of 6 is 720

     

  2. To write a recursive function to print the Fibonacci series up to a given number and write the series up to 89.

    #include <stdio.h>

    #include <conio.h>

    unsigned long ...

Get Discrete Mathematics now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.