I have recursive function,that i need to convert into iterative version... but can't understand how to do it - 2 hours at least :(

double sequence(int n)
{
	double sum,i;
	
	if(n <= 30) return 2*n;
	else
	{
		for(sum =0,i = 1;i <= 30;i++)
			sum+= sequence(n-i);

		return sum/30;
	}
}

I dont understand the meaning of assigning 0 to sum in the for loop. If you would assign 0 to it why do you bother calculating it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.