inbuilt function to find factorial in c++ code example
Example 1: factorial in c++
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int fact(int i){
if (i <= 1) return 1;
else return i*fact(i-1);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
cout << fact(N) << "\n";
return 0;
}
Example 2: built in function in c++ for binary to decimal
#include <bits/stdc++.h>
using namespace std;
int main(void){
bitset<8> bits("1000");
int ab = bits.to_ulong();
cout << ab << "\n";
return 0;
}
Example 3: recursive function for fibonacci series in java javascript
var fib = function(n) {
if (n === 1) {
return [0, 1];
} else {
var arr = fib(n - 1);
arr.push(arr[arr.length - 1] + arr[arr.length - 2]);
return arr;
}
};
console.log(fib(8));