int main()
{
printf("Hello,World!\n");
}
|
| Hello,World! |
/*****************************************************
This example shows how to use comments
******************************************************/
int main(){ /* main program always starts this way */
MakeView(200,80); // make a view of size 200x80
SetColor(100,0,0); // set drawing color to 100 % red
MoveTo(20,50); // move pen to drawing position
FontInfo(22,0,0); // the first argument must be 12, 16 or 22
DrawString("Hello, World!"); // draw string at the current pen position
GifOut(); // output the buffered drawing to GIF format data
} /* main program always ends this way */
|
|
/*****************************************************
Roots of Quadratic Equation
(x-2)(x-1)=0
******************************************************/
int main()
{
double a,b,c,d;
a=1.;
b=-3.;
c=2.;
d=(-b+sqrt(b*b-4.*a*c))/(2.*a);
printf("d=%8.4f\n",d);
d=(-b-sqrt(b*b-4.*a*c))/(2.*a);
printf("d=%8.4f\n",d);
}
|
|
d= 2.0000 d= 1.0000 |
/*****************************************************
Trigonometric Functions
******************************************************/
int main()
{
int i;
double a[11];
double pi2;
for(i=0;i<11;i=i+1) a[i]=0.1*i; // i++ style not supported
pi2=3.1415926536/2.;
for(i=0;i<11;i=i+1){
printf("%5i %5.3f %12.8e\n",i,a[i],sin(pi2*a[i]));
}
}
|
|
0 0.000 0.00000000e+00 1 0.100 1.56434465e-01 2 0.200 3.09016994e-01 3 0.300 4.53990500e-01 4 0.400 5.87785252e-01 5 0.500 7.07106781e-01 6 0.600 8.09016994e-01 7 0.700 8.91006524e-01 8 0.800 9.51056516e-01 9 0.900 9.87688341e-01 10 1.000 1.00000000e+00 |