The road stripe painters have formed a union. Each painter will only paint a sec
ID: 3864506 • Letter: T
Question
The road stripe painters have formed a union. Each painter will only paint a section of 2 miles of stripes on the road and charge $200 for the service. If the road is longer than 2 miles, the painter will divide the road into three equal parts, and subcontract each of those parts to three other painters, charging $100 to hire the three painters. Each of the hired painters will do the same thing as the painter who hired them. If their section is 2 miles or less, they will paint it and charge $200, otherwise they will divide their section into three parts, charge $100 and hire three more painters, and so on. Write a recursive function which is used to solve the above problem.
Problem must be written in C The protoype for the function must be: int costofpainting(double length);
Write a driver to test the function with the appropriate test cases. The driver obtains the input and prints the output.
Explanation / Answer
#include<stdio.h>
int costofpainting(double length);
void main()
{
int c=costofpainting(2700);
printf("%d",c);
}
int costofpainting(double length)
{
if(length>200)
{
return (100+costofpainting((double)(length/3))+costofpainting((double)(length/3))+costofpainting((double)(length/3)));
}
else
return(200);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.