Program to calculate Minimum Cost
#include <stdio.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("\nMINIMUM COST = %.2f AT p = %.1f\n",cost,p);
getch();
}
#include <stdio.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("\nMINIMUM COST = %.2f AT p = %.1f\n",cost,p);
getch();
}
No comments:
Post a Comment