Casio FX-890P Owner's Manual page 86

Casio personal computer owner's manual
Table of Contents

Advertisement

Making your program easy to read
You have probably noticed by now that we have been writing and editing our C
programs in a certain format. The previous program was written and entered as:
main(){
printf("How are you?¥n");
printf("Fine,thank you¥n");
}
We could have just as easily written and input it as:
main(){
printf("How are you?¥nFine,thank you¥n");
}
Or even:
main(){printf("How are you?¥nFine,thank you¥n");}
The computer would execute the program identically in either case. The first format is
preferred, however, because it is much easier to read. Though you may not see the
need for such a format at this point, but when you start dealing with longer programs
you will greatly appreciate an easier to read format.
Creating a program to output numeric values
C programs can output octal, decimal, and hexadecimal values. Here, let's create a
program that displays the vale 65 in its decimal, hexadecimal and floating-point
format, using a few more new techniques.
First, enter the editor and input the following:
/* Output Value */
main(){
printf("D=%d H=%x F=%f¥n"65,65,65.0);
}
The first line is what we call a comment line. The computer reads everything between
/* and */ as a comment, and so they are ignored. You can use comment lines inside
of a program to point out certain features, or as memos for later reference.
Putting /* and */ around program statements is as well a good way to temporarily
forbid the interpreter executing them without deleting them for good.
The remainder of the program is quite similar to the one that we created to output
character strings to the display, but the argument for printf() looks a bit different. The
commas inside of the parentheses are there to separate arguments. This means that
the printf statement in this program has a total of four arguments.
printf("D=%d H=%x F=%f¥n"65,65,65.0);
The arguments inside the parenthesis of printf tell the computer to print the following:
D=<65 as decimal integer> H=<65 as hexadecimal> F=<65.0 as floating point>
st
| 1
argument |
|
| 2
th
|
| 4
argument
rd
| 3
argument
nd
argument
86

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Z-1grZ-1

Table of Contents