286 views
0 votes
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.

Related questions

1 votes
1 votes
3 answers
1
jverma asked May 23, 2022
1,071 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 votes
0 votes
0 answers
2
5 votes
5 votes
1 answer
3
srestha asked Aug 6, 2018
590 views
How will this function run for the input 123 (where str points '123' and n=3)?in myAtoiRec(int *str,int n) { if(n==1) return*str-'0'; return(10*myAtoiRec(str,n-1)+str[n-1...
1 votes
1 votes
2 answers
4
Anjana Babu asked Dec 21, 2016
551 views
Write C Program using Recursive Funtions for the Problem Described below and Analyse the Complexity Of the CodeProblemGiven an unordered array arr[] which contains n di...