Answer:
The answer to this question can be given as:
function [change,flag]=makeChangeRecursive(cost,paid)
//define function
change=[];
flag=false; //use flag for true or false.
if((paid-cost)>=100) //checking condition value greater then equal to 100
[m,f]=makeChangeRecursive(cost,paid-100);
change=[100;m];
flag=true;
return;
elseif((paid-cost)>=50) //checking condition value greater then equal to 50
[m,f]=makeChangeRecursive(cost,paid-50); //holding value.
change=[50;m];
flag=true;
return;
elseif((paid-cost)>=20) //checking condition value greater then equal to 20
[m,f]=makeChangeRecursive(cost,paid-20);
change=[20;m];
flag=true;
return;
elseif((paid-cost)>=10) //checking condition value greater then equal to 10
[m,f]=makeChangeRecursive(cost,paid-10);
change=[10;m];
flag=true;
return;
elseif((paid-cost)>=5) //checking condition value greater then equal to 5
[m,f]=makeChangeRecursive(cost,paid-5);
change=[5;m];
flag=true;
return;
elseif((paid-cost)>=2) //checking condition value greater then equal to 2
[m,f]=makeChangeRecursive(cost,paid-2);
change=[2;m];
flag=true;
return;
elseif((paid-cost)>=1) //checking condition value greater then equal to 1
[m,f]=makeChangeRecursive(cost,paid-1);
change=[1;m];
flag=true;
return;
elseif((paid-cost)<0) //checking condition value less then 0
warning('That''s not enough to but an item.'); //print message
flag=false;
return;
elseif(paid==cost) //checking condition if value is equal.
flag=1; //falg value.
change=[];
return;
end
end //end function
Explanation:
In the above program code the function must use the recursion to change the variable.This function run in 4 case i.e. case 1 In this case when we pass the value [change,flag]=makeChangeRecursive(2,100) in the function so the change value will be 50,20,20,5,2,1,and flag= ,1. In case 2 when we pass the value(3,20) in the function so the change value will be 10,5,2,and flag= ,1. In case 3 when we pass the value(20,20) in the function so the change value will be change= {},flag= 1. In case 4 when we pass the value(59,20) in the function so the change value will be warning message i.e That''s not enough to but an item.