SlideServe
Menu
Préférences
© SlideServe · v2026

Input and Output (1)

astra avatar
15 diapositives · 330 Views · Sep 30, 2014

Input and Output (1). Output Statement. Output Statement. Display text on the screen You can display a string , and any other variables There are two output statements in Pascal write writeln. write statement. Syntax: write ( <output list> )

Input and Output (1) - slide 1
01 / 15Input and Output (1)
1 / 17

Télécharger la présentation

Input and Output (1)
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Input and Output (1) Output Statement

  2. Output Statement • Display text on the screen • You can display a string, and any other variables • There are two output statements in Pascal • write • writeln

  3. write statement • Syntax: • write ( <output list> ) • <output list> could be a single expression or a list of expressions separated by commas • Each of these expressions may be a constant, variable or a formula (expression)

  4. write statement (cont.) • Some examples • write ( ‘hello’ ); • write ( 1234567 ); • write ( 3 * 6 ); • Output variables • var Num1 : integer; • Num1 := 10; • write ( Num1 );

  5. More than one expression • To output more than one expression in one statement, use commas to separate expressions • Example: • write ( ‘I am ‘, ‘Mr. Wong’); • I am Mr. Wong • write ( ‘2 + 3 = ‘, 2 + 3 ); • 2 + 3 = 5

  6. space Output integer and real • integer variables are output as they are • write ( 10 ); 10 • write ( -10 ); -10 • real variables are output in exponential form • write ( 135.0 ); b1.35000000E+02 • write ( -135.0 ); -1.35000000E+02

  7. Formatted Output • Formatting integer values • write ( <integer expression>:<w> ); • The number w specify the number of characters to display • The integer is displayed right-aligned, and blanks are added in front of it if the length of the integer is shorter than w • If the length of the integer is lager than w , the whole integer is displayed

  8. Formatted Output • Examples on formatted integer output • write ( 1234:7 ); • bbb1234 • write ( 1234:4 ); • 1234 • write ( 1234:2 ); • 1234

  9. Formatted Output • Formatting real values • write ( <real expression>:<w>:<d> ); • The number w specify the total number of characters to display, and d specify the number of decimal places to display • The real number is displayed right-aligned, and blanks are added in front of it if the length of the real value is smaller than w

  10. Formatted Output • Formatting real values (cont.) • If the length of a real value is lager than w , the whole number is displayed • If the number of decimal is larger than d, the value is rounded to d decimal places • If d is not given, the value is displayed in exponential form

  11. Formatted Output • Examples on formatted real values output • write ( 12.45:10:4 ); • bbb12.4500 • write ( 12.45:10:2 ); • bbbbb12.45 • write ( 12.45:10:1 ); • bbbbbb12.5 • write ( 12.45:10 ); • b1.245E+01

  12. Formatted Output • Formatting strings and characters • write ( <string or character>:<w> ); • The number w specify the number of characters to display • The character(s) are displayed right-aligned, and blanks are added in front of it if the length is shorter than w • If the length is lager than w , the whole string / character is displayed

  13. Formatted Output • Examples on formatted string / character output • write ( ‘A’:4 ); • bbbA • write ( ‘ABCDEF4’:3 ); • ABCDEF4

  14. writeln statement • writeln statement is similar to the write statement except that the cursor is advanced to the next line after the output is displayed • An empty writeln statement (no argument given) will curse the cursor to advance to a new line

  15. writeln statement • Example 1 • write ( ‘I am ’ ); • writeln ( ‘Mr. Wong’ ); • Example 2 • writeln ( ‘I am Mr. Wong’ ); • Example 3 • write ( ‘I am ’ ); • write ( ‘Mr. Wong’); • writeln; • All these three examples result in same output