Construiti functii recursive pentru combinari, cmmdc, suma cifrelor, numarul de cifre, cifra maxima.
Răspunsuri la întrebare
#include <iostream>
using namespace std;
long long cmbinari(long long n,long long k,long long n2){
if(n==k){
return 1;
}else{
return cmbinari(n-1,k,n2)*n/(n-k);
}
}
int cmmdc(int a, int b)
{
int r;
r=a%b;
if(r)
return cmmdc(b,r);
else
return b;
}
int sumcif(int a){
if(a==0)
return 0;
else
return sumcif(a/10)+a%10;
}
int nrcif(int a){
if(a==0)
return 0;
else
return nrcif(a/10)+1;
}
int maxim=0;
void cifmax(int n,int& maxim){
if(n==0){
return ;
}else{
if(n%10>maxim){
maxim=n%10;
}
cifmax(n/10,maxim);
}
}
int main(){
long long n,k,n2;
cin>>n>>k;
n2=n;
cout<<cmbinari(n,k,n2)<<endl;
int a,b;
cin>>a>>b;
cout<<cmmdc(a,b)<<endl;
cout<<sumcif(a)<<endl;
cout<<nrcif(a)<<endl;
cifmax(a,maxim);
cout<<maxim;
return 0;
}