There are two output statement in Pascal write

  • Slides: 12
Download presentation

There are two output statement in Pascal : write , writeln. The writeln statement

There are two output statement in Pascal : write , writeln. The writeln statement Writeln ( <output list>) Printing a number Statement Output Writeln ( -123 ) -123 Writeln ( 123. 0 ) 1. 230000 E+02 Writeln ( 0. 0000123 ) 1. 230000 E-05

Printing a character and a string Statement Writeln ( ‘Hello!!’) Output Hello!! Writeln (‘How

Printing a character and a string Statement Writeln ( ‘Hello!!’) Output Hello!! Writeln (‘How are you? ’) How are you? Writeln (‘Item Price’) Item Price Printing a list of data items Statement Writeln (‘A’, ’B’, ’C’) Output ABC Writeln (‘Hello’, ’John’) Hello. John Writeln (‘Item’, ‘Price’) Item. Price Writeln ( 1, ‘+’, 2, ‘is’, 3) 1+2 is 3 Writeln (‘Program’, 123) Program 123

Performing calculation Statement Writeln (1 + 2 + 3 + 4) Output 10 Writeln

Performing calculation Statement Writeln (1 + 2 + 3 + 4) Output 10 Writeln (10 * 4) 40 Writeln ( 1. 25 + 2. 0) 3. 250000 E+00

Printing values of variable Program Personal. Particulars; writeln ( Height ); Var Name :

Printing values of variable Program Personal. Particulars; writeln ( Height ); Var Name : string; end. Sex : char; Age : integer; Height : real; Begin Name : = ‘Jacky Cheung’; Sex : = ‘M’; Age : = 15; Height : = 1. 75; writeln ( Name ); writeln ( Sex ); writeln ( Age );

Jacky Cheung M 15 1. 750000 E+00 The write statement Program Welcome; Begin write

Jacky Cheung M 15 1. 750000 E+00 The write statement Program Welcome; Begin write ( ‘Hello’); write ( ‘Welcome to Pascal programming’) End. Hello. Welcome to Pascal programming

The writeln statement with no output list Program Introducing. Myself; Begin Write ( ‘My

The writeln statement with no output list Program Introducing. Myself; Begin Write ( ‘My name is John’ ); Writeln ( ‘How do you do? ) End. My name is John How do you do?

Formatted integer values Statement Writeln ( 1234: 7 ) Output Bbb 1234 Writeln (

Formatted integer values Statement Writeln ( 1234: 7 ) Output Bbb 1234 Writeln ( 1234: 5 ) B 1234 Writeln ( -1234: 5 ) -1234 Writeln ( -1234: 6 ) B-1234 Writeln ( -1234: 7 ) Bb-1234 Statement Writeln ( 1234: 3) 1234 Writeln ( 1234: 1) 1234 Writeln ( 1234: 0) 1234 Output

Formatting real values Statement Output Writeln ( 12. 35: 10: 4 ) Bbb 12.

Formatting real values Statement Output Writeln ( 12. 35: 10: 4 ) Bbb 12. 3500 Writeln ( 12. 35: 10: 1 ) Bbbbbb 12. 4 Writeln ( 12. 35: 8: 1 ) Bbbb 12. 4 Writeln ( 12. 35: 8: 0 ) Bbbbbb 12 Writeln ( -12. 35: 10: 2 ) Bbbb-12. 35 Writeln ( 12. 35: 10 ) B 1. 235 E+01 Writeln ( 12. 35: 8 ) B 1. 2 E+01 Writeln ( 12. 35: 1: 4) 12. 3500 Writeln ( 12. 35: 1: 2) 12. 35

Formatting strings and characters Statement Output Writeln ( ‘A’: 6 ) bbbbb. A Writeln

Formatting strings and characters Statement Output Writeln ( ‘A’: 6 ) bbbbb. A Writeln ( ‘AB’: 6 ) bbbb. AB Writeln ( ‘ABC’: 6 ) bbb. ABC Writeln ( ‘ABC’: 5 ) bb. ABC Writeln ( ‘ABC’: 4 ) b. ABC Writeln ( ‘ABC’: 3 ) ABC Writeln ( ‘ABC’: 2 ) ABC Writeln ( ‘ABC’: 1 ) ABC Writeln ( ‘ABC’: 0 ) ABC

Input with prompt messages Program Accounting; Var Income, Expense, Balance : real; Begin writeln

Input with prompt messages Program Accounting; Var Income, Expense, Balance : real; Begin writeln ( ‘Enter income and expense: ’ ); readln ( Income, Expense ); Balance : = Income – Expense; writeln ( ‘The balance is $’, Balance: 1: 2 ) End. Enter income and expense: 1000 125 1001 The balance is $875. 00