Saturday, 1 April 2017

Hacker Rank Solution Program In C++ For " Day 9: Recursion "

Problem :- Day 9: Recursion

Submit Your Solution Here :- Click Here

Copy The Color Code and paste it into hackerrank Editor .

Solution :-

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int factorial(int num) ;

int main() {
    int n;
    cin >> n;
    cout << factorial(n) << endl;
    return 0;
}

int factorial(int num) 
{
    if(num == 1)
    {
        return 1;
    }
    else 
    {
    return (num * (factorial(num-1)));
    }
}

Output :-

Hacker Rank Solution Program In C++ For " Day 9: Recursion "

No comments:
Write comments

Recommended Posts × +