Home > Casio > Personal Computer > Casio Z1 Gr User Manual

Casio Z1 Gr User Manual

Here you can view all the pages of manual Casio Z1 Gr User Manual. The Casio manuals for Personal Computer are available online for free. You can easily download all the documents as PDF.

Page 91

  91  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  */ /* #include  */ main(){  float x;  printf(“Input Value(DEG)“);  scanf(“%f”,&x);  angle(0); /* Degrees */  printf(“sin(%f)=%f¥n“,x,sin(x));...

Page 92

  92  6.2.4 Using selection statements  Using the “if” selection statement  You can use the “if” statement to tell the computer to shift the flow of control if certain conditions are met. The “if” statement has two basic formats.  1. if (condition) statement. Here, the statement is executed if the condition is met (true = any value other than 0), and not executed if the condition is not met (false = 0).  2. if (condition) statement 1   else statement 2 In this case, statement 1 is executed if the...

Page 93

  93 /* Quadratic equation */ /* #include  */ /* #include  */ main(){  double a,b,c,D,q,r;  scanf(“%lf %lf %lf“,&a,&b,&c);  D=b*b-4.0*a*c;  if (d>=0){   q=(-b+sqrt(D))/a/2.0;   r=(-b-sqrt(D))/a/2.0;   printf(“%If, %If¥n“,q,r);  }  else{   r=sqrt(-D)/a/2.0;   q=-b/a/2.0;   printf(“%lf+%lfi  “,q,r);   printf(“%lf-%lfi¥n“,q,r);  } }  The variables “a”, “b” and “c” correspond to the “a”, “b”, and “c” in the quadratic equation, while the “D” variable is the “D” of the discriminant. Variables “q” and “r” are...

Page 94

  94  6.2.5 Using loops  Using the “while” loop  The “while” loop makes it possible to repeat execution of statements until a specific condition is met. The format of the “while” loop is as follows:  while (condition)  Statement  The “while” loop first executes the condition. If the condition is met (true, returning a value other than 0), the statement is executed, and execution loops back to the “while” loop to evaluate the condition again. Whenever the condition is not met (false, returning 0),...

Page 95

  95 Using the #define statement  Lines 3 and line 4 of the program contain the #define statement. The #define statement defines a name for a particular string of characters. In the above program, “#define STR ‘0’ “ tells the computer that anytime it comes across the name “STR”, it should replace it with the character “0”. Likewise, “#define END ‘Z’ “ tells the computer that the name “END” is to be replaced by the character ‘Z’.  The reason for using a #define statement is to make the program easier to...

Page 96

  96  Using the “do – while” loop  The “do – while” loop is another method that you can use for repeat execution. The format of the “do – while” loop is as follows:  do  Statement while (condition);  Unlike the “while” loop, the “do – while” loop executes the statement first and then checks whether or not the condition has been met or not. Note also the semicolon at the end of the “while” line cannot be omitted. Let’s use the “do – while” to find the Greatest Common Measure for two values.  /* Greatest...

Page 97

  97  Note the following:  for (i=0; i

Page 98

  98  Nested loops  The term nested loop means simply “loops inside of loops”. To better understand how nested loops work, let’s have a look at a very short, simple representative program.  /* nested loops example */ /* #include  */ main(){  float a[3][3];  int i,j;  for (i=0; i

Page 99

  99 We have now the value assignment nested loop we saw before, followed by a similar set of loops to read and display the values after they are stored. The only new item is the “%8.2f” which specifies that each value will be displayed in an area of at least 8 characters, with two decimal places (right flush). .R   U   N  . . 1 . . 2 . . 3 . . 4 . . 5 . . 6 . . 7 . . 8 . . 9 . .      1.00    2.00    3.00     4.00    5.00    6.00     7.00    8.00    9.00 >_ 6.2.6 Defining functions  Function...

Page 100

  100  Arguments Arguments are used to pass values to the function when it is called. If no values are passed, the arguments can be omitted. If the arguments are omitted, the following argument type declaration is also omitted.  Argument type declaration Declares the types of the arguments specified above. Note that ANSI C allows declaring arguments directly inside the parenthesis. The C interpreter does not allow such a declaration.  Statements The portion of the function between the braces is executed...
Start reading Casio Z1 Gr User Manual
All Casio manuals