수행시간 소스좀 도와주세요
도리도리
2023.04.01
질문 제목 : 수행시간소스수행시간질문 내용 :
#include stdio.h
#include stdlib.h
#include time.h
double power(double x, int n)
void main (void)
{
double x,i;
clock_t start, finish;
double duration;
//?
finish = clock();
duration = (double)(finish - start) / clocks_per_sec;
printf(%f 초입니다.\n, duration);
}
double power(double x, int n)
{
if(n==0) return 1;
else if((n%2)==0)
return power(x*x, n/2);
else return x*power(x*x, (n-1)/2);
}
double power(double x, int n)
{
if(n==0) return 1;
else if((n%2)==0)
return power(x*x, n/2);
else return x*power(x*x, (n-1)/2);
}이 소스에서 물음표 있는 곳에 소스를 어떻게 작성해야 순환적 거듭제곱 수행시간을 만들 수 있나요??
답변부탁드립니다.
-
두힘
start = clock();
함수 소환!!!
finish = clock(); // 이 라인은 올리신 코드에 있습니다.
이렇게 하시면 될 것 같습니다.