Professional Documents
Culture Documents
Basic Input Edward MEcija
Basic Input Edward MEcija
Basic Input Edward MEcija
Example
2
5+5
THE SUM
is 10
Write
a program
to compute the area of a circle use the formula
2
A=r
Where Pi=3.1416
Algorithm
Input- Enter Radius (R)
Process- Compute Area
(A=Pi*r*r)
Output- Display A
Program
Program Area;
Uses CRT;
CONST
Pi=3.1416;
VAR
R: Integer;
A: Real;
BEGIN
CLRSCR;
WriteLN (`Enter Radius`);
ReadLN (R);
A=Pi*r*r;
WriteLN (`THE AREA , A: 8,2`);
ReadLN;
End.
Output
Enter Radius
1
The Area: Pi=3.1416
Short If Then-Else
Write a program that determines if the input numbers is
equivalent to the magic words `ILOVEYOU` if not. Display the
result `ILOVEYOU` if the input is 143 and `WRONG GUESS` if it is
not.
Algorithm
Enter Your Guess Number (N)
IF (N=143) then
WriteLN (`143 is ILOVEYOU`)
ELSE
WriteLN (`WRONG GUESS`)
PROGRAM
Program Magic Number;
USES CRT;
VAR
N: INTEGER;
BEGIN
CLRSCR;
WriteLN (`ENTER YOUR GUESS NUMBER`)
ReadLN (N);
If (N=143) then
OUTPUT
Enter Your Guess Number
143
143 is ILOVEYOU
Example 2
Write a program that determines if the input number is positive or
negative consider 0 as positive number.
ALGORITHM
Enter a number (N)
IF (N>=0) then
WriteLN (`POSITIVE`)
ELSE
WriteLN (`NEGATIVE`)
PROGRAM
Program POSNEG;
Uses CRT;
VAR
N: Integer;
Begin
CLRSCR
WRITELN (`ENTER YOUR NUMBER`)
READLN (N);
IF (N>=0) then
WriteLN (`POSITIVE`)
Else
WriteLN (`NEGATIVE`);
ReadLN;
End.
OUTPUT
Enter Your Number
5
Positive
LONG IF-THEN-ELSE
Write a program that will assist a teacher in calculating student
grades at the END of the semester it accepts a numerical grade
as input then it will display the character grade as output based
on the given scale.
Range
Grade
90 and above
80-89
70-79
60-69
Below 60
ALGORITHM
Enter Grade (G)
If (G>=90) then
WriteLN (`A`)
Else if (G>=80) then
WriteLN (`B`)
Else if (G>=70) then
WriteLN (`C`)
Else if (G>=60) then
WriteLN (`D`)
Else
WriteLN (`F`)
Program
Program Grade;
Uses CRT;
VAR
G: Integer;
BEGIN
WriteLN (`Enter Grade`);
ReadLN (G);
IF (G>=90) then
WriteLN (`A`)
Else if (G>=80) then
WriteLN (`B`)
Else if (G>=70) then
WriteLN (`C`)
Else if (G>=60) then
WriteLN (`D`)
Else
WriteLN (`F`);
ReadLN;
End.
OUTPUT
ENTER GRADE
70
Your Grade2is C
Example
Colors
B or b
Blue
R or r
Red
G or g
Green
Y or y
Yellow
Other color
unknown color
ALGORITHM
Enter a letter (L)
If (L=`B`) or (L=`b`) then
WriteLN (`BLUE`)
If (L=`R`) or (L=`r`) then
WriteLN (`Red`)
If (L=`G`) or (L=`g`) then
WriteLn (`Green`)
If (L=`Y`) or (L=`y`) then
WriteLN (`Yellow`)
Else
WriteLN (`Unknown Color`);
Program
Program Color;
Uses CRT;
VAR
L: Char;
BEGIN
CLRSCR;
Grade
A
80-89
70-79
60-69
50-59
Others
F
act of range
ALGORITHM
Enter Grade (G)
Case G of
90..100: WriteLN (`A`);
80..89: WriteLN (`B`);
70..79: WriteLN (`C`);
60..69: WriteLN (`D`);
50..59: WriteLN (`F`);
Else
WriteLN (`Out of Range`);
End;
Program
Program;
Uses CRT;
VAR
G: Integer;
BEGIN
CLRSCR;
WriteLN (`Enter Grade`);
ReadLN (`G`);
Case of G
90.100: WriteLN (`A`);
80..89: WriteLN (`B`);
70..79: WriteLN (`C`);
60..69: WriteLN (`D`);
50..59: WriteLN (`F`);
Else
WriteLN (`OUT OF ORDER`);
End;
ReadLN;
End.
OUTPUT
Enter A Grade
85
Your Grade2is B
Example
Color
`B` or `b`
Blue
`R` or `r`
Red
`G` or `g`
Green
`Y` or `y`
Yellow
Other color
ALGORITHM
Unknown Color
PROGRAM
Program Color;
Uses CRT;
VAR
L: Char;
BEGIN
CLRSCR;
WriteLN (`Enter Color`);
ReadLN (C);
Color is
Write
a Green
program that generates the given sequence numbers.
1
2
3
4
5
ALGORITHM
N: =1
While (N<=5) do
Begin
WriteLN (N);
N=N+1
End.
PROGRAM
Program Sequence 1;
USES CRT;
VAR
N: INTEGER;
Begin
CLRSCR;
WRITELN (`WHILE DO LOOP-INCREMENTATION`);
N: =1;
While (N<=5) DO
BEGIN
WRITELN (N);
Delay (140000);
END;
READLN;
END.
PROGRAM SEQUENCE 2;
USES CRT;
VAR N: Integer;
CLRSCR;
Example 2
Write a program that generates the given sequence numbers
5
4
3
2
1
ALGORITHM
N: =5;
WHILE (N>=1) DO
BEGIN
WRITELN (N);
N:=N-1:
END.
PROGRAM
Program Sequence 1;
Uses CRT;
VAR N: INTEGER;
BEGIN
CLRSCR;
WRITELN (`WHILE DO LOOP-DECREASE`);
N: =5:
WHILE (N>=1) DO
BEGIN
WRITELN (N);
N: =N-1;
DELAY (19000);
END;
READLN;
END.
PROGRAM SEQUENCE 2;
USES CRT;
VAR N: INTEGER;
BEGIN
CLRSCR;