Factorial
#include<iostream>Cmmdc provaidat de algoritmul d-lui Euclid
using namespace std;
int factorial(int n)
{if(n==0)
return 1;
else return n*factorial(n-1);
}
int main()
{int n;
cin>>n;
cout<<factorial(n);
}
#include<iostream>Să se afişeze toate prefixele unui numar natural n
using namespace std;
int cmmdc(int a, int b)
{ if(b==0)
return a;
else return cmmdc(b, a%b);
}
int main()
{int a,b;
cin>>a>>b;
cout<<cmmdc(a,b);
}
#include<iostream>Suma cifrelor unui număr
using namespace std;
void prefix(int n)
{if(n!=0)
cout<<n<<endl;
prefix(n/10);
}
int main()
{int n;
cin>>n;
prefix(n);
}
#include<iostream>Numărul de cifre impare dintr-un număr
using namespace std;
int suma(int n)
{if(n==0)
return 0;
else return n%10+suma(n/10);
}
int main()
{int n;
cin>>n;
cout<<suma(n);
}
#include<iostream>
using namespace std;
int nrimp(int n)
{if(n==0)
return 0;
else return n%2+nrimp(n/10);
}
int main()
{int n;
cin>>n;
cout<<nrimp(n);
}