-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursive
More file actions
37 lines (31 loc) · 781 Bytes
/
Recursive
File metadata and controls
37 lines (31 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <string>
#include <iomanip>
#include <windows.h>
using namespace std;
int RecursionF (int num);
int main(){
LARGE_INTEGER startTime,endTime,freq;
double times;
QueryPerformanceFrequency(&freq);
int num;
cout<<"enter a num "<<endl;
cin>>num;
QueryPerformanceCounter(&startTime);
cout<<RecursionF(num)<<endl;
QueryPerformanceCounter(&endTime);
times=((double)endTime.QuadPart-(double)startTime.QuadPart)
/freq.QuadPart;
cout<<"used time : ";
cout<<fixed<<setprecision(20)<<times<< ' s ' <<endl;
system ("pause");
return 0;
}
int RecursionF (int n){
if (n==1){
return 0;}
if (n%2==0){
n= n/2;}
else
n=3*n+1;
return 1+RecursionF(n);}