Text Box: What is Pascal?
Pascal is a computer programming language named after the seventeen century mathematician Blaise Pascal.

What are the Basic format of a Pascal program?

Program TITLE ;
Uses wincrt ;
Begin
Clrscr ;
Program Statements ;
Program statement ;
End.

Program - It is the first word of all Pascal Programs. It is a keyword (you cannot use keyboard to describe variable)

Title - It is the name of the program. It is an identifier. Identifiers begin with a letter , and then followed by any digit, letter or the underscore character. ( _ )

Uses Wincrt - It is indicating that windows environment is used in your program.

Begin - It defines the starting point of the program.

Clrscr - It is to clear the console screen.

Program Statements - They are commands or instructions to the computer which performs various tasks.

End - This must always be the final statement of a pascal program.


OUTPUT

The keywords write and write and writeln

WRITE

The write statement leaves the cursor at the end of the current output (it doesnot go to the next line)

WRITELN

The writeln leaves the cursor at beginning of the next line ( it goes to the next line )

All these commands are being instructed by the compiler

What is the main difference between writeln and write statement?

In both the write and writeln statement gives the same output but in writeln the cursor moves to the next line but in write the cursor doesn't move.

Example with write

Program MyName ;

Begin 
	Write (“Ruwinda”) ;
	Write (“Niloshan “) ;
	Write (“Fernando”) ;
End.

As a result it displayed on the screen.
		

	RuwindaNiloshanFernando



Example with writeln

Program MyName;

Begin 
	Writeln (“Ruwinda”);
	Writeln (“Niloshan”);
	Writeln (“Fernando”);
End.

		Ruwinda
		Fernando
		Niloshan


Pascal Variable

What is variables?
1)Integer
2)Char
3)String
4)Boolean
5)Real

What is Integer? 
Integer variable store whole numbers. Range is –32,768 to 32,767.

What is Char?
Character variable can store only one character.

What is String?
String can store more the one character up to 256 character.

What is Boolean?
Boolean variable can store on of  2 possible states true or false.

What is real?
Can store positive and negative number which include decimal places such as 34.2 , -3.55.

What are the rules you have to follow to introduce a variable to a program?
First you have to identify the data type and the size of the variable you are going to use.
You have to introduce (declare) these are the variable we are going to use.
The  section of the declaration area. This declaration must directly after the program heading and is marked by the VAR keyboard.
The variable name are maximum   of  32 alphanumeric characters. First letter of the data name must be alphabetic (A - Z)
We cannot use scientific symbols ,keyboards ,space for variable declaration .

How to use pascal variables in programs ?
Declaring a variable
			Var name : data type ;
Example of variable declarations
			Number : Integer ;
			Name     : String ;
			Average : Real ;

What is the assigning operator ?

 The “:=” operator allows data to a variable to be assignment to a variable.

Example

Program VariableIntroduction;

		VAR
		      X:string ;

Begin

		X := “Ruwinda” ;
		Write x ;

End.

Result Ruwinda



Input 3 numbers and calculate the average. If the average is greater than 75 display ‘pass’ otherwise display ‘fail’.

Program Numbers;
Uses wincrt;
VAR
Num_1,num_2,num_3,tot,avg ; Integer;
Begin
Clrscr;
Write (“enter num_1”);
Readln (num _1);
Write (“enter num 2”);
Readln (num _2); 
Write (“enter number 3”);
Readln (num_3);
tot := num_1+num_2+num_3;
avg := tot/3;
If (avg > 75)then
writeln (“pass”);
Else
Writeln (“fail”);
End.

PASCAL PROGRAMMING

[HOME]  [2]  [3]  [4]  [5]  [6]  [7]  [8]  [9]  [10]  [11]  [12]  [13]  [14]  [15]  [16]  [17]  [18]  [19]  [20]  [21]  [22]  [23]  [24]  [25]  [26]  [27]  [28]  [29] [30]  [31]  [32]  [33] 

<<[PREVIOUS]                   [NEXT]>>

 

 

www.kiddiesnet.com