# Factorial, power2, Fabinascii Practice

Sun Jan 15 2023 22:00:03 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

```//Factorial
#include <bits/stdc++.h>
using namespace std;

int fac(int n)
{
//Base call and return must be there
if(n==0) return 1;
return n*fac(n-1);
}
int main() {
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int ans = fac(n);
cout<<ans<<"\n";
}
return 0;
}

//Power 2
#include <bits/stdc++.h>
using namespace std;

long long powerofto(long long n)
{
if(n==0) return 1;
return 2*powerofto(n-1);
}
int main() {
int t;
cin>>t;
while(t--)
{
long long n;
cin>>n;
long long ans=powerofto(n);
cout<<ans<<"\n";
}
return 0;
}

//print count
#include <bits/stdc++.h>
using namespace std;

void printcnt(int n)
{
if(n==0) return;

//cout<<n<<" ";
printcnt(n-1);
cout<<n<<" ";
}
int main() {
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
printcnt(n);
cout<<"\n";
}
return 0;
}

//Reach destination
#include <bits/stdc++.h>
using namespace std;

void reachome(int dest, int src)
{
if(src==dest)
{
cout<<src<<" Pahunchh gya: ";
return;

}
cout<<src<<" ";
src++;
reachome(dest, src);
}
int main() {
int t;
cin>>t;
while(t--)
{
int dest;
int src;
cin>>dest;
cin>>src;
reachome(dest,src);
cout<<"\n";
}
return 0;
}

//Fabinascii series
#include <bits/stdc++.h>
using namespace std;

int fab(int n)
{
if(n==1) return 1;
if(n==0) return 0;
return fab(n-1)+fab(n-2);
}
int main() {
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int ans=fab(n);
cout<<ans<<"\n";
}
return 0;
}

//Print digits in string
#include <bits/stdc++.h>
using namespace std;

void print(int n, string arr[])
{
if(n==0) return;
int digit = n%10;
n=n/10;

print(n,arr);
cout<<arr[digit]<<" ";
}
int main() {
int t;
cin>>t;
while(t--)
{
string arr[10]={"zero", "one","two","three","four","five","six","seven","eight","nine"};
int n;
cin>>n;
print(n,arr);
cout<<"\n";
}
return 0;
}

```
content_copyCOPY