In this tutorial, we are going to write a C Program of a minimum cost problem in C Programming with practical program code and step-by-step full complete explanation.
C Program of the minimum cost problem.
#include<stdio.h> #include<conio.h> void main() { float p, cost, p1, cost1; for(p=0; p<=10; p=p+0.1) { cost=40-8*p+p*p; if(p==0) { cost1=cost; continue; } if(cost>=cost1) break; cost1=cost; p1=p; } p=(p+p1)/2.0; cost=40-8*p+p*p; printf("MINIMUM COST = %2f AT p=%.1f", cost,p); }
Output
MINIMUM COST = 24.00 AT p=4.0