﻿ C program for the surface area of an egg body
```
// Calculation Program for the surface area of an egg body, 08 (Tues.) Dec., 2009

// egg equation: (x*x+y*y)**2=a*(x**3)+(a-b)*x*(y**2), The case that a=4 and b=3.2 (or, a=1 and b=0.8) may be the nearest shape to an actual egg.
// The general condition needs b<=a, and in the case of b=0, the curve is led to a circle.

// file name: surface.c

#include< stdio.h>
#include< math.h>

void main(void)
{
double a,b,x,dx,y,xmax,s,ds,dydx,p;

// Setting of the constants
for(;;)
{
printf("Input of constant a; a= ? ");
scanf("%lf",&a);
if(a>0)
{
break;
}
else
{
printf("Please input the value of a after correcting a as a>0.\n");
}
}
for(;;)
{
printf("Input of constant b; b= ? ");
scanf("%lf",&b);
if(b>=0&&b<=a)
{
break;
}
else
{
printf("Pleease input the value of b after correcting b as 0< b < a or b=0 or b=a.\n");
}
}

printf("\n");

p=3.1415927;
xmax=a;// the maximum value of x
dx=xmax/1000000;

// execution of calculation
if(b==0)
{
s=p*a*a;
}
else
{
for(x=dx;x<=xmax;x=x+dx)
{
y=sqrt(((a-b-2*x)+sqrt(4*b*x+(a-b)*(a-b)))*x/2);// containing the equation of sphere "y=sqrt(a*a/2/2-(x-a/2)*(x-a/2))" in the case of b=O
dydx=(1/(2.0*sqrt(2.0)))*sqrt((a-b-2.0*x+sqrt(4.0*b*x+(a-b)*(a-b)))/x)+(sqrt(x/2.0))*((b/sqrt(4.0*b*x+(a-b)*(a-b))-1)/sqrt(a-b-2.0*x+sqrt(4.0*b*x+(a-b)*(a-b))));
ds=2*p*y*sqrt(1+dydx*dydx)*dx;
s=s+ds;
}
}

printf("The surface area of the egg body; S=%lf\n",s);
printf("\n");

printf("end\n");
}// the end of the program

```

RETURN