494 views
0 0 votes

How will this code work? Which output will give? Any error?

#include <stdio.h>
 
double recurCutting(int *p,int n){
	int i,max,tmp;
	if(n<1) return 0;
	 max=p[n];
	for(i=1;i<n;i++){
		tmp=p[i]+recurCutting(p,n-i);
		if(tmp>max){
			max=tmp;
		}
 
	}
	printf("%d",max);
	return max;
}
 
int main(void) {
	int prices[]={0,1,3,3,5,5,7,8,3,10,10};
	recurCutting(&prices,10);
	return 0;
}

 

Please log in or register to answer this question.

Position:
Show:

Related questions

5 5 votes
2 2 answers
224
224 views
GO Classes asked Jun 13
224 views
What is the output of the following code?#include <stdio.h int sum(int n) { if (n == 1) return 1; return n + sum(n - 1); } int main() { printf("%d", sum(5)); return 0; }
1 1 vote
2 2 answers
513
513 views
Vishnu__ asked Feb 4
513 views
#include <stdio.h>int mystery(int n) { if (n == 0) { return 0; } else if (n % 2 == 0) { return mystery(n / 2); } else { return 1 + mystery(n...
2 2 votes
3 answers 3 answers
1.8k
1.8k views
jverma asked May 23, 2022
1,845 views
#include <stdio.h>int f(int n){ static int r = 0; if (n <= 0) return 1; r=n; return f(n-1) + r;}int main() { printf("output is %d", f(5)); return 0;}Ou...
0 0 votes
0 0 answers
2.7k
2.7k views
Na462 asked Aug 22, 2018
2,708 views
Let R represents class of Recursive Programs and I denotes class of Iterative Program. Which of them is incorrect ?A. Some Program belonging to R doesn't Terminate.B. For...