我编的一个计算各个函数所用时间的c程序 为什么总会出现floating point error:Domain?

来源:百度知道 编辑:UC知道 时间:2024/06/11 03:57:35
#include<stdio.h>
#include <time.h>

main()
{
double x;
int n,k;
long i;
double al1();
double al2recur();
double al2itera();
double pow();
int test();

printf("please enter base and power:\n");
scanf("%lf %d",&x,&n);
printf("please enter the algorithm you wish to use:\n");
scanf("%d",&k);

switch(k)
{
case 1: al1(x,n); break;

case 2: al2recur(x,n); break;

case 3: al2itera(x,n); break;

default: printf("please enter 1,2 or 3!\n");
}

test(x,n,k);

}

double al1(double x,int n)
{
double y;
y=1;
while(n>0){
y=x*y;
n--;
}
printf("the result is %lf\n",y);
}

double al2recu

//long i;
i宏定义后,后面未使用,可将其注释掉.
另外有几个地方的函数要求有返回值
我把程序改成如下以后用C文件运行无错误和警告,但由于不是我自己编的程序所以也只能如此.

#include<stdio.h>
#include <time.h>

main()
{
double x;
int n,k;
//long i;
double al1();
double al2recur();
double al2itera();
double pow();
int test();

printf("please enter base and power:\n");
scanf("%lf %d",&x,&n);
printf("please enter the algorithm you wish to use:\n");
scanf("%d",&k);

switch(k)
{
case 1: al1(x,n); break;

case 2: al2recur(x,n); break;

case 3: al2itera(x,n); break;

default: printf("please enter 1,2 or 3!\n");
}

test(x,n,k);

}

double al1(double x,int n)
{
double y;
y=1;
while(n>0){
y=x*y;
n--;
}
printf("the result is %lf&