Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这道题目用递归写为什么是Runtime Error呢?请高手指教下

Posted by huicpc21 at 2006-04-18 21:57:11 on Problem 2601
#include<stdio.h>
#include<math.h>
double C[4000],A[4000];
int n;
double calculate(int i)
{
	double temp;
	if(i==0)
		return A[0];
	if(i==n+1)
		return A[n+1];
	temp=(calculate(i-1)+calculate(i+1))/2-C[i];
	return (calculate(i-1)+calculate(i+1))/2-C[i];
}
int main()
{
	int i;
	double result;
	scanf("%d",&n);
	scanf("%lf%lf",&A[0],&A[n+1]);
	for(i=1;i<=n;i++)
		scanf("%lf",&C[i]);
	result=calculate(1);
	printf("%.2lf\n",result);
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator