• We need your support!

    We are currently struggling to cover the operational costs of Xtremepapers, as a result we might have to shut this website down. Please donate if we have helped you and help make a difference in other students' lives!
    Click here to Donate Now (View Announcement)

Algorithm design

Messages
4
Reaction score
1
Points
13
Algorithm are step by step solutions to problems
they follow the format
input --> process --> output
 
Messages
4
Reaction score
1
Points
13
ok
There are mainly four types of statements
1)sequentional
2)logical (decision making)
3)iterative (looping)
4) sub programs ( module)

the third iterative I do it when I have a set of statements I would like to repeat
ok
the first question
how many time do you want to repeat them ?
Looping is like counting
if you are counting from 1 to 10 then you counted 10 elements
if you are counting from 0 to 10 then you counted 11 elements

so if I want to repeat 10 times and I am starting from 0 I will go till 9

ok who will keep track of the counting some one has to here is the x
I will by saying listen you will start to count from 0 and each time you will
increase by 1. ok to infinite or till a certain number
here where the while comes in
while condition is satisfied do the following statements but listen the number of time
will be controlled by the counter.
 
Messages
318
Reaction score
336
Points
73
Anyone explain me the question from past paper Oct Nov 2011..

Write an algorithm using psudocode which input
input 1000 numbers
Output many of these numbers were whole numbers were whole numbers (integars)
(U may use INT(X) in ur ans e.g INT (3.8) gives the value of Y = 3)
 
Messages
419
Reaction score
690
Points
103
Anyone explain me the question from past paper Oct Nov 2011..

Write an algorithm using psudocode which input
input 1000 numbers
Output many of these numbers were whole numbers were whole numbers (integars)
(U may use INT(X) in ur ans e.g INT (3.8) gives the value of Y = 3)

for x = 1 to 1000
input number
difference = INT(number) – number
if difference = 0 then total = total + 1
next x
print total

tricky part with this question is to incorporate use of function INT(X)

INT(X) actually truncates the decimal part of a decimal number and returns only whole number
e.g.

INT(1.2)=1
INT(2.6)=2
INT(3.4)=3
INT(4.9)=4
INT(6)=6
INT(11)=11

(note this is not rounding because 2.6 becomes 2 not 3)



Now if you input the number 7 which is whole number then difference will be 9-9=0 so total will be incremented by 1. If you input sth decimal like 7.3 then diff will be 7-7.3= -0.3 which is not equal to zero so total will remain unchanged.
 
Messages
365
Reaction score
335
Points
73
Could someone tell me that when to use END IF and ELSE IF while writing algorithm ??
 
Messages
1,222
Reaction score
2,628
Points
273
Could someone tell me that when to use END IF and ELSE IF while writing algorithm ??

END IF is used after the IF....ELSE structure for e.g

If Number>100 then total=total+1
else X=X+1
endif

hope this helps? ^^
 
Messages
255
Reaction score
122
Points
53
hey can u please post a sample ? from the question paper with solution? it'll make it more easier then..
and i also need notes on logic gates.
 
Messages
1,222
Reaction score
2,628
Points
273
I'm still trying to master algorithms ^^'


NOV 2010 Q17 P11
A school is doing a check on the heights and weights of all its students. The school has
1000 students.

Write an algorithm, using pseudocode or a flowchart, which
• inputs the height and weight of all 1000 students
• outputs the average (mean) height and weight
• includes any necessary error traps for the input of height and weight

Here I'm gonna use Total height as TH and total weight as TW..

TH=o
TW=0
For Count=1 to 1000
Input Height
If Height>0 then TH=Height+TH
else print "error"
end if
Input Weight
If Weight>o then TW=Weight+TW
else print "error"
end if
Next count
Average Height=TH/1000
Average Weight=TW/1000
Print Average Height
Print Average Weight
 
Messages
1,222
Reaction score
2,628
Points
273
Ok I just solved this question. I don't know if its correct or not :/

Write an algorithm, using pseudocode or a program flowchart only, that:
• inputs a series of positive numbers (-1 is used to terminate the input),
• outputs how many numbers were less than 1000 and
• outputs how many numbers were greater than 1000.

A=0
B=0
Repeat
Input Number
If Number>1000 then A=A+1
else B=B+1
end if
Until Number <=-1
Print A
Print B
 
Top