Casio FX-890P Owner's Manual page 91

Casio personal computer owner's manual
Table of Contents

Advertisement

Entering Values
Now, let's try a program that calculates the sine and cosine of values that you enter
from the keyboard. Since we can be expecting decimal values for input and output,
we will be defining the variable as floating-point. The program to accomplish this task
would appear as follows:
/* Compute sine & cosine */
/* #include <stdio.h> */
/* #include <math.h> */
main(){
float x;
printf("Input Value(DEG)");
scanf("%f",&x);
angle(0); /* Degrees */
printf("sin(%f)=%f¥n",x,sin(x));
printf("cos(%f)=%f¥n",x,cos(x));
}
First, we must specify the variable x as floating point.
The scanf() function is used to get the entry of a value from the keyboard. Exactly the
opposite as the printf() function, the first argument of the scanf() determines the type,
and the value is assigned to the second argument. In the program here, we can see
that the first argument of scanf() is "%f", to indicate floating point format. The second
argument is &x which is a pointer to the variable x. A pointer indicates the address in
memory of a variable. The second argument of the scanf() function must be a
pointer.
The statement "angle(0);" specifies the unit of angular measurement. You can specify
the unit by changing the argument of angle() as follows:
• angle(0) – degrees
• angle(1) – radians
• angle(2) – grads
The next statements are the now familiar printf().
After you input this program, enter the interpreter and execute it.
When the computer reaches the scanf() function, it displays the message "Input
Value(DEG)" and waits for input of a value. Here, let's enter 60 and press the .
key. This value is assigned to variable "x", and the following appears on the display.
.R U N .
.
60 .
.
sin(60.000000)=0.866025
cos(60.000000)=0.500000
>_
91
.

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Z-1grZ-1

Table of Contents