EasyManua.ls Logo

Casio FX-890P - Page 101

Casio FX-890P
126 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
101
/* 100 squares 3 */
/* #include <stdio.h> */
double dsquare(x) /* square */
double x;
{
return (x*x);
}
main(){
double d;
for (d=1.0; d<=100.0; d+=1.0)
printf(“(%lf)^2=%f¥n”,i,dsquare(d));
getchar(); /* waits ret key */
}
Variables are now declared as double precision floating-point. Variables declaration
has to happen before using them in a statement.
Note that we have to start the program with the function, in order to allow calling it
further down.
EXAMPLE 3:
The alternative method is to use declare the function first, so that the interpreter
knows its type, before actually writing the function. Here is an example using function
declaration
/* 100 squares 4 */
/* #include <stdio.h> */
extern double dsquare();
main(){
double d;
for (d=1.0; d<=100.0; d+=1.0)
printf(“(%lf)^2=%f¥n”,i,dsquare(d));
getchar(); /* waits ret key */
}
double dsquare(x) /* square */
double x;
{
return (x*x);
}
Note that a function declaration of line 3 does not specify the amount and type of
parameters. ANSI C authorizes function prototyping, which would look like:
extern double dsquare(double)
Nevertheless, prototyping is not implemented in the C interpreter of the unit. It is
therefore recommended to write functions before calling them, avoiding parameter
errors that can be hard to debug.

Table of Contents

Related product manuals