Professional Documents
Culture Documents
Recursion
Recursion
#include <iostream>
using namespace std;
int a1,d,n,an;
int f (int n) {
if (n>1) return f(n-1)+d;
else return a1;
}
main(){
cin>>a1>>d>>n;
cout<<f(n)<<endl;
}
2. ნატურალური n რიცხვის ფაქტორიალი n! ვუწოდოთ ნამრავლი:
n!=1*2*3*…*n. შეადგინეთ პროგრამა, რომლითაც დაითვლით მოცემული
რიცხვის ფაქტორიალს:
ა) ციკლის გამოყენებით,
ბ) რეკურსიული ფუნქციის გამოყენებით.