Pascal Programs Notes
Pascal Programs Notes
Program 2
Program 5
Program Write_and_Writeln;
Uses crt; Program Unformatted_reals;
Begin Uses crt;
clrscr; Begin
writeln('Hello'); clrscr;
writeln('How'); writeln('100.25 => ',100.25);
writeln('Are'); writeln('0.3 => ',0.3);
writeln('You'); writeln('4.0 => ',4.0);
write('Hello '); writeln('-45.56E5 => ',-45.56E5);
write('How '); writeln('0.56E-5 => ',0.56E-5);
write('Are '); readln;
write('You '); End.
readln;
End.
Program 6
Program Formatted_reals;
Program 3 Uses crt;
Program Print_integer; Begin
Uses crt; clrscr;
Begin writeln(100.25:10:2);
clrscr; writeln(0.00356:10:4);
writeln(100); writeln(4.0:10:3);
writeln(+23); writeln(-45.56E5:10:2);
writeln(-12); writeln(0.56E-5:10:2);
writeln(0); writeln(25.25:10:2,12.253:10:3);
readln; readln;
End. End.
[Type here] [Type here] [Type here]
Program 7 Program 9
Program Math; Program Inputs;
Uses crt; Uses crt;
Begin var Mark,Total:integer;
clrscr; Avg:Real;
Writeln('100 devided by 5 is = ',100/5); Begin
Writeln('5 squared is = ',sqr(5)); clrscr;
Writeln('Square root of 100 is = ',sqrt(100)); Total:=0;
Writeln('Balance of 10 devided by 3 is = ',10 mod 3); writeln('Input Marks for Subject 1');
Writeln('Quotient of 10 devided by 3 is = ',10 div 3); readln(mark);
Writeln('Rounded value of 5.635 is = ',round(5.635)); Total:=Total+Mark;
Writeln('For MOD & DIV number must be integer'); writeln('Input Marks for Subject 2');
readln; readln(mark);
end. Total:=Total+Mark;
writeln('Input Marks for Subject 3');
readln(mark);
Total:=Total+Mark;
Program 8
Avg:=Total/3;
Program Variables; writeln('Total is ',Total);
Uses crt; writeln('Average is', Avg:6:2);
varMath,ICT,Eng,Total:integer; readln;
Average:Real; End.
Begin
clrscr; Program 10
Math:=75;
ICT:=62;
Program Char_String;
Eng:=65;
Uses crt;
Total:=Math+ICT+Eng;
varch:char;
Average:=Total/3;
st:string;
writeln('Total is ',Total);
Begin
writeln('Average is', Average:6:2);
clrscr;
readln;
write('Press any character');
readln(ch);
write('Type your name');
readln(st);
How do you modify the above program to writeln('You Press ' ,ch);
writeln('Your name is ',st);
get the following output?
readln
Marks Sheet End.
==========
Math 75
ICT 62
English 65
Totalhere]
[Type 202 [Type here] [Type here]
Average 67.33
Program 11
Program 12 Begin
Read marks
Pseudo code If marks >=75 then
Grade=”A”
Begin Else if marks >=65 then
Read math marks Grade=”B”
Read science marks Else if marks >=50 then
if math marks >=50 and science marks>=50 then Grade=”C”
display “You are selected” Else if marks >=35 then
else Grade=”S”
display “You are not selected” Else
Endif Grade=”W”
End If
Program 13 display Grade
End
Pseudo code
Program Cases;
Begin Program 17
Uses crt;
Read the price of an apple
var
if price >=50 then
Grade:Char;
display “Price is too high”
Begin
display “Don’t buy today”
clrscr;
else
write('Entet your Grade ');
display “Price is OK”
readln(Grade);
display “You may buy”
case grade of
Endif
'A':Write('Excelent');
'B':Write(' Very Good ');
Program 18 'C':Write(' Good');
Write a program using CASE statement to print 'S':Write(' Study hard ');
[Type here] [Type here] [Type
'W':Write(' Try it again '); here]
the number of days of the month when the
number of the month is given. else
write('Error in grade');
Program 19 Write the program 16 using CASE statement.
Repetition Statements
Program 20 Program 30
Program RepeatUntil;
Uses crt;
var Program 38
x:integer;
Begin program ArrayTotal;
clrscr; Uses crt;
x:=1; var
repeat M:array[0..4] of integer;
writeln('ICT'); i,Tot:integer;
x:=x+1; Begin
until x>10 ; clrscr;
readln; Tot:=0;
End. for i:= 0 to 4 do
begin
write('Enter marks');
Program 35
readln(m[i]);
Pseudo code end;
for i:= 0 to 4 do
Begin tot:=tot+m[i];
Total=0 writeln('Total is ',tot);
Counter=0 readln;
While counter<=10 End.
Read marks
Add marks to the total
Add one to the counter Program 39
End while Find the maximum number from
Calculate the average the given 10 numbers.
Display the average
[Type here]
End [Type here] [Type here]
Program 36. Rewrite the above program
using the REPEAT UNTIL statement.
Program 40
Write a program to read and store your name letter by letter and then print the name.
Functions and Procedures
Program 41 Program 42
Program Functions; Program Procedures;
Uses Crt; Uses Crt;
var N1,N2,Answer: Integer; var N1,N2,Ans: Integer;
Program 43 Program 44
Program Functions; Program Procedurs;
Uses crt; Uses crt;
var var
Num:integer; Num:integer;
Res:Boolean; Ans:Boolean;
Function IsOdd(x:Integer): boolean; Procedure IsOdd(x:Integer; var
res:boolean);
Begin
if x mod 2<>0 then Begin
IsOdd:=true if x mod 2<>0 then
else res:=true
IsOdd:=false; else
End; res:=false;
Begin if Res=true then
clrscr; write('Odd Number')
write('Entet a Number '); else
readln(Num); write('Even Number');
IsOdd(Num); End;
Res:=IsOdd(Num); Begin
if Res=true then clrscr;
write('Odd Number') write('Entet a Number ');
else
[Type here] [Type here]readln(Num); [Type here]
write('Even Number'); IsOdd(Num,ans);
readln; readln;
45.Write a program to output the maximum number from given three numbers.
46.Write a program to print whether the triangle is scalene, isosceles or
equilateral when three sides are given.
47.Write a program to convert between Celsius and Fahrenheit temperatures.
9 5
F = C x 5 + 32 C = (F-32) x 9
50.Write a program to read & store the numbers and print the total & average by
terminating the program if zero has to be entered.
51.Write a program to print the Fibonacci sequence from 0 to 1000
Note. The Fibonacci sequence is a series of numbers where a number is
found by adding up the two numbers before it.
52.Write a program to find the factorial of given positive number.
53.Write a program to consider the problem of determining whether the number
given, is aPrime number.
54.Write a program to read and store 10 different values of integer and
a. Store the above values after multiplying by 3
b. Store the values after dividing by 3
c. Store the remainder after dividing by 3