O'Reilly logo

Discrete Mathematics by Babu Ram

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required