Pseudocode
Pseudocode
Q. Write a pseudocode to input some positive numbers and display the total and counting of those
numbers.
Arrays
Same datatype and name for many values
mark mark mark mark mark mark mark mark mark mark
5 6 7 100 23 9 1 25 34 76
0 1 2 3 4 5 6 7 8 9
5,6,7,100,23,9,1,25,34,76
//Write in an array
FOR Counter = 0 TO 9
INPUT mark[Counter]
NEXT Counter
FOR Counter = 0 TO 9
OUTPUT mark[Counter]
NEXT Counter
Highest= 0
Lowest=100
Total= 0
Counter=0
Classsize=0
Input classSize
FOR counter = 0 to 10
Total=Total+ mark[counter]
Then
Highest= mark[counter]
Endif
Then
Lowest = mark[counter]
Endif
NEXT Counter
Output highest
Output lowest
Output total/10
#Calculate and output highest, lowest, average for unknown classsize.
DECLARE mark: ARRAY[0:50] OF INTEGER
Highest= 0
Lowest=100
Total= 0
Counter=0
Classsize=0
Input classSize
Total=Total+ mark[counter]
Then
Highest= mark[counter]
Endif
Then
Lowest = mark[counter]
Endif
NEXT Counter
Output highest
Output lowest
Output total/classSize
//Declaring all the variables with meaningful names
DECLARE TotalMark : ARRAY[1:50] OF INTEGER
DECLARE AverageMark : ARRAY[1:50] OF INTEGER
DECLARE SubjectCounter, StudentCounter, DistinctionNo, MeritNo, PassNo, FailNo :
INTEGER
CONSTANT Distinction = 70
CONSTANT Merit = 55
CONSTANT Pass = 40
DistinctionNo = 0
MeritNo = 0
PassNo = 0
FailNo = 0
AverageMark[StudentCounter] = INT((TotalMark[StudentCounter]/SubjectNo)
OUTPUT "Name" , StudentName[StudentCounter]
OUTPUT "Combined Total Mark" , TotalMark[StudentCounter]
OUTPUT "Average Mark" , AverageMark[StudentCounter]
NEXT StudentCounter
Provided:
Teamname[leaguesize]
TeamName
Team A Team B Team C Team D Team E
Teampoints[matchno][leaguesize]
Total points(tbc)
Team A 3 2 3 1+2+3……..= total
(1,1) (1,2) (1,3)
League size
TeamPoints[teamcounter, matchcounter]
Rule 2: Declare all the variables for which totals need to be displayed.
Output1 : counts the total number of away wins, home wins, drawn matches and lost matches
for each team
Output 2: total points
DECLARE TeamPoints : INTEGER
DECLARE AwayWinNo : INTEGER
DECLARE HomeWinNo : INTEGER
DECLARE DrawNo : INTEGER
DECLARE LostNo : INTEGER
Rule 3: Declare variables for highest and lowest or max and min.
Note: Spot the word ‘all’ in the output for declaring array and ‘each’ for declaring variable.
Rule: Constants will be declared for each comparison value like grades or points
Constant awaywin = 3
Constant homewin = 2
Constant drawnmatch = 1
Constant lostmatch = 0
calculates the total points for all matches played for each team
DECLARE ARRAY : TotalPoints[1:leaguesize]
0 0 0 0 0 0 0 0 0
TotalPoints
// Initialization
FOR TeamCounter= 1 to leaguesize
TotalPoints[TeamCounter] = 0
NEXT TeamCounter
Highestpoints = 0
lowestpoint=1000