P5739 [Example 7] 7. The deep-yl recursive version factorial

P5739 [Example 7] 7. The deep-yl factorial

Description Title
seek n! (N≤12), i.e. 1 × 2 × 3 ... × n .

Challenge: Try not to use loop statements (for, while) to complete this task.

Input formats
without

Output format
without

Sample Input Output
Input
3
outputs
6

Honestly recursion to the (*. *)

#include<bits/stdc++.h>
using namespace std;
long long th(long long int a,long long int &last){
	if(a==1){
		return last;
	}
	else{
		last*=a;
		th(a-1,last);
	}
}
int main(){
	long long int i=1,n,last=1;
	cin>>n;
	printf("%lld",th(n,last));
	return 0;
}
Published 35 original articles · won praise 29 · views 1017

Guess you like

Origin blog.csdn.net/bupt_sanqing/article/details/104797291