Part 1 Implement the recursive algorithms in the notes title

Part 1. Implement the recursive algorithms in the notes titled Recursion1: factorial, sum, Fibonacci, print, & palindrome.

Part 2. Implement a recursive algorithm to sum the first N integers

Solution

#include <stdio.h>

#include <conio.h>

void main()

{

   int a, b, c, d;

   clrscr();

   printf(\"Enter two numbers a, b\ \");

   scanf(\"%d%d\", &a, &b);

   c = recgcd(a, b);

   printf(\"The gcd of two numbers using recursion is %d\ \", c);

   d = nonrecgcd(a, b);

   printf(\"The gcd of two numbers using nonrecursion is %d\", d);

   getch();

}

int recgcd(int x, int y)

{

   if(y == 0)

   {

     return(x);

   }

   else

   {

     return(recgcd(y, x % y));

   }

}

int nonrecgcd(int x, int y)

{

   int z;

   while(x % y != 0)

   {

    z = x % y;

    x = y;

    y = z;

   }

   return(y);

}

2)

#include <stdio.h>

int addNumbers(int n);

int main()

{

    int num;

    printf(\"Enter a positive integer: \");

    scanf(\"%d\", &num);

    printf(\"Sum = %d\",addNumbers(num));

    return 0;

}

int addNumbers(int n)

{

    if(n != 0)

        return n + addNumbers(n-1);

    else

        return n;

}

Part 1. Implement the recursive algorithms in the notes titled Recursion1: factorial, sum, Fibonacci, print, & palindrome. Part 2. Implement a recursive alg
Part 1. Implement the recursive algorithms in the notes titled Recursion1: factorial, sum, Fibonacci, print, & palindrome. Part 2. Implement a recursive alg

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site