On the image the highlighted 0.03 should be 0.04 but showing 0.03 and coin needed should be 10 but showing 9
My Code:
#include <stdio.h>
int main(){
double coins[6] = {0.01,0.05,0.10,0.25,1,2};
double ans[15];
double V = 5.64;
int j=0,i=5,Tcoin = 0;
while(V>coins[0])
{
if(coins[i]<=V)
{
j = V/coins[i];
//printf("%.2lf - %.2lf = %.2lf\n",V,j*coins[i],V-(j*coins[i]));//This is for testing purpose
V = V-(j*coins[i]);
Tcoin += j;
}
i--;
}
printf("Number of coin needed is: %d\n",Tcoin);
return 0;
}