function procedure c6 c7
TRANSCRIPT
Pascal Programming Language
Omar ElSabek & Fayez GhazzawiIT Engineering3th year – UNKNOWN Department
• Procedures and Functions
• The most important material
• which are very important and you should keep on practicing more often.
• Pascal provides two kinds of subprograms:
• Functions : these subprograms return a single value.
• Procedures : these subprograms do not return a value directly.
• Procedures are just like small programs.
• Sometimes they are called sub--programs. They help the programmer to avoid repetitions.
• A procedure start off with a begin and ends up with an end;.
• It can also have its own variables, which cannot be used with the main-program.
Procedure Procedure name( Var Variable Name : Type );
Program Lesson1_Program1 (input,output);
Var
Procedure Square(X : Integer; Var y : Integer);
var
Begin
…………
End;
Begin
………….
End.
There is a Two type of Variables :
Global Variables :
That which we define in Program Var
Local Variable :That Which we define inside of our procedure/function or
in procedure/function signature
What is the signature !!!
Procedure Procedure name( Var Variable Name : Type );Var Variable Name : Type
Program Lesson1_Program1 (input,output);
Var
Z :integer ;
Procedure Square(X : Integer; Var y : Integer);
var
moxo :real ;
Begin
…………
End;
Begin
………….
End.
Program Lesson1_Program1 (input,output);
Var
Z :integer ;
Procedure Square(X : Integer ; Var y : Integer);
var
moxo :real ;
Begin
…………
End;
Begin
………….
End.
When you declare parameters to a procedure, variables must separated
by a semi-colon ";".They are put in between the brackets, following the
procedure name.
Program Lesson1_Program1 (input,output);
Var
X , Z : integer ;
Procedure Square(R : Integer ; Var Result : Integer);
Begin
Result := R * R ;
End;
Begin
Readln(X);
Square(X,Z);
Writeln('The square of X is: '); Writeln( Z );
End.
Program Lesson1_Program1 (input,output);
Var
X , Z : integer ;
Procedure Square(R : Integer);
Var
Result : Integer;
Begin
Result := R * R ;
writeln ('The square of X is: ' , Result);
End;
Begin
Readln(X);
Square(X);
End.
• ABS( -5 ) 5
• Chr( 97 ) a
• Ord( ‘ a ’ ) 97
• Sin(x) Cos(x)
• Pred( 6 ) 5
• Sqr( 3 ) 9
• Sqrt( 9 ) 3
• Odd( 3 ) True
• Even( 3 ) False
• Succ ( 5 ) 6
• Function are The second type of sub-program .
• The only difference from the procedure is that the Function return a value at the end.
• A Function start off with a begin and ends up with an end;.
• It can also have its own variables, which cannot be used with the main-program.
Function FunctionName(Var VariableName:Type): Return Type;
Program Lesson1_Program1 (input,output);
Var
Function Square(X : Integer): Integer ;
var
Begin
…………
End;
Begin
………….
End.