i have tried implement two methods recursive and dynamic method and both took 0 second it means that no one is better in my computer or something is wrong in code? here is these methods
1// recursive
#include <stdio.h>
#include <time.h>
#include <iostream>
using std::cout;
void print(int n){
if (n<0) return ;
cout<<n<<" ";
print(n-1);
}
int main(){
int n=10;
time_t start,end;
double dif;
time(&start);
print(n);
time(&end);
dif=difftime(end,start);
printf("it took you %.21f seconds ",dif);
return 0;
}
2.second method
#include <iostream>
#include <stdio.h>
#include <time.h>
using namespace std;
void print (int n){
if (n<0) return ;
while (n>=0){
cout<<n--<<endl;
}
}
int main(){
int n=10;
double dif;
time_t start,end;
time(&start);
print(n);
time(&end);
dif=difftime(end,start);
printf("it took you %.21f seconds",dif);
return 0;
}