T. Combination – Codeforces Problem Solution in C++

Disclaimer: Make sure you tried enough before checking the solution

Problem: https://codeforces.com/group/MWSDmqGsZm/contest/223339/problem/T

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstring>
using namespace std;

long long int comb(int n, int r)
{

    if (r == 0)
    {
        return 1;
    }
    else
    {
        return ((n * comb(n - 1, r - 1)) / r);
    }
}
int main()
{
    int n, r;
    cin >> n >> r;

    cout << comb(n, r);
}

Assiut University Training – Newcomers Solution Recursion

Leave a Comment