当前位置:编程学习 > C/C++ >>

求C语言改错...

#include <stdio.h> int main(void) { int n; double x,root; printf("Enter x:"); scanf("%lf",&x); printf("Enter n:"); scanf("%d",&n); root=fun(n,x); printf("Root=%0.2f\n",root); return 0; } double fun(int n,double x) { if(n == 1) return 1; else return x* fun(n-1,x); } 给出DEBUG --------------------Configuration: a11 - Win32 Debug-------------------- Compiling... a01.cpp C:\Documents and Settings\a11\a01.cpp(11) : error C2065: 'fun' : undeclared identifier C:\Documents and Settings\a11\a01.cpp(17) : error C2373: 'fun' : redefinition; different type modifiers Error executing cl.exe. a01.obj - 2 error(s), 0 warning(s)
答案:#include <stdio.h>

double fun(int n,double x);/*加上这句话.你老师没告诉你,要么main函数写最后,要么在前面要写函数声明吗*/
int main(void)
{
	int n;
	double x,root;

	printf("Enter x:");
	scanf("%lf",&x);
	printf("Enter n:");
	scanf("%d",&n);
	root=fun(n,x);
	printf("Root=%0.2f\n",root);

	return 0;
}
double fun(int n,double x)
{
	if(n == 1)
		return 1;
	else
		return x* fun(n-1,x);
}
其他:#include <stdio.h>
double fun(int n,double x);//!!!!
int main(void)
{
	int n;
	double x,root;

	printf("Enter x:");
	scanf("%lf",&x);
	printf("Enter n:");
	scanf("%d",&n);
	root=fun(n,x);
	printf("Root=%0.2f\n",root);

	return 0;
}
double fun(int n,double x)
{
	if(n == 1)
		return 1;
	else
		return x* fun(n-1,x);
}

上一个:c语言编程问题
下一个:C语言中,对一个 int 型数据用 sizeof ,为什么得出的结果是4?int 占的字节不是 2 吗?我用的是VC++6.0。

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,