samedi 31 octobre 2020

C++ factorial execution time [closed]

I am confuse to why this piece of code does not work.Can someone please help me to why it does not show the time taken to find the factorial in the end?Thank you in advance.

#include<iostream>
#include <time.h>
using namespace std;
int main()
{
    int n,faktoriel=1;
    cout << "n= "; cin >> n;
    clock_t tStart = clock();
    for (int i = 1; i<= n; i++)
    {
        faktoriel = faktoriel * i;
    }
    cout <<"Faktoriel < "<<n<<" > = "<< faktoriel<<endl;
    cout<<("Time taken:", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire