Is this algoritham and pseudo correct

  • Thread starter Thread starter PainterGuy
  • Start date Start date
AI Thread Summary
The discussion revolves around creating an algorithm and pseudocode to sort five numbers (A, B, C, D, E) in descending order. Participants suggest using a list or array to simplify comparisons, iterating through the numbers to identify and print the largest while removing it from the list until only one number remains. There is a debate about the clarity and detail required in the algorithm, particularly regarding how to compare multiple numbers at once. Some contributors emphasize that comparisons must be made two at a time, which necessitates a more detailed approach in the algorithm. Overall, the conversation highlights the importance of structure and clarity in algorithm design for effective programming.
PainterGuy
Messages
938
Reaction score
72
hello nice people,

i was writing a algorithm and psedo for some problem here:
[Link Removed]

is there someone who will help me to correct it? you can edit it there on the docs. much grateful for any help you can give me.

cheers
 
Last edited:
Physics news on Phys.org
Why don't you just enter what you did right here?
painterguy said:
Five numbers denoted by the variables A, B, C, D, and E are supplied as input. Write an algorithm and pseudocode to print these numbers in descending order of magnitude.

Step 1: Read the input data
Step 2: Compare A, B, C, D, and E
Step 3: Print the largest of five
Step 4: Compare the remaining four numbers
Step 5: Print the largest of four
Step 6: Compare the remaining three numbers
Step 7: Print the largest of three
Step 8: Compare the remaining two numbers
Step 9: Print the largest of two
Step 10: Print the last remaining number
Step 11: Stop

Read the input data
DO WHILE the numbers A, B, C, D, and E are not in descending order
How do you compare five numbers? I know how to compare two numbers, but I don't know how to compare five of them at the same time.
 
Mark44, could you remove that quoted text from your post please, if you don't mind? actually i want to change something in that text. if it's possible please do it. i am very grateful for your help.

cheers
 
Last edited:
Just copy it from what's in my post and paste it in your reply. You can make changes there.
 
Mark44 said:
I know how to compare two numbers, but I don't know how to compare five of them at the same time.

EDIT: To do what the OP wants (based on the quoted text by yourself) is actually relatively simple.

Put the numbers into a list / array. Write a simply function to iterate through the numbers and hold the largest*, print it, remove it from the list. Repeat until list is down to one item and print.

What language are you required to do this in painterguy?

* Example:

Take A, is B bigger than A? No. Hold A.
Is C bigger than A? Yes. Hold C.
And so on through the whole list / array.
Once complete, print that value and remove it from the list.
Repeat.

You would have to build in something to handle equal values.
 
jarednjames said:
EDIT: To do what the OP wants (based on the quoted text by yourself) is actually relatively simple.

Put the numbers into a list / array. Write a simply function to iterate through the numbers and hold the largest*, print it, remove it from the list. Repeat until list is down to one item and print.

What language are you required to do this in painterguy?

* Example:

Take A, is B bigger than A? No. Hold A.
Is C bigger than A? Yes. Hold C.
And so on through the whole list / array.
Once complete, print that value and remove it from the list.
Repeat.

You would have to build in something to handle equal values.

hello everyone,:smile:

i want to write this in english. many thanks for helping me out.

cheers:smile:
 
painterguy said:
hello everyone,:smile:

i want to write this in english. many thanks for helping me out.

cheers:smile:

I meant programming language.
 
jarednjames said:
I meant programming language.

until now i do not know because i know almost nothing about programming!:shy:

many thanks

cheers:smile:
 
painterguy said:
until now i do not know because i know almost nothing about programming!:shy:

many thanks

cheers:smile:

But you're asked to write an algorithm as well as a pseudocode.
 
  • #10
jarednjames said:
But you're asked to write an algorithm as well as a pseudocode.

hello,:smile:

yes i too want to write pseudo code. i do not know if pseudo code is require for programming. some good people on this forums are teaching me the basics of programming. :approve:

you can see my algo and pseudo here:--
https://www.physicsforums.com/showthread.php?t=484875

cheers:smile:
 
  • #11
painterguy said:
hello,:smile:

yes i too want to write pseudo code. i do not know if pseudo code is require for programming. some good people on this forums are teaching me the basics of programming. :approve:

you can see my algo and pseudo here:--
https://www.physicsforums.com/showthread.php?t=484875

cheers:smile:

Ah I see, your fine then. That looks ok.

I thought they wanted the actual coding algorithm for the task.
 
  • #12
jarednjames said:
Ah I see, your fine then. That looks ok.

I thought they wanted the actual coding algorithm for the task.

many thanks for your reply. so my algo on 2nd post of Mark44 correct?:rolleyes:

is coding algorithm different from normal english algorithm? some one has told me that first your write algorithm in english then you transfer every statement in english algorithm into code of program language you use.

cheers:smile:
 
  • #13
painterguy said:
many thanks for your reply. so my algo on 2nd post of Mark44 correct?:rolleyes:

Seems ok. Could do with more detail for the comparison section though.
is coding algorithm different from normal english algorithm? some one has told me that first your write algorithm in english then you transfer every statement in english algorithm into code of program language you use.

Well the code version will be what's used in the program itself.

If you are planning a function you should write out what you want it to do and then convert it to code - just gives you a bit of structure and makes things easier.
 
  • #14
jarednjames said:
Seems ok. Could do with more detail for the comparison section though.

Well the code version will be what's used in the program itself.

If you are planning a function you should write out what you want it to do and then convert it to code - just gives you a bit of structure and makes things easier.

many thanks jarednjames.:smile:

it will be a normal english algorithm then. will it not be?:confused: but i think it will be little more technical, will be short, and will require careful thinking than normal english algorithm which i have written. tell me please is it so?

much grateful for helping me out.

cheers:smile:
 
  • #15
painterguy said:
many thanks jarednjames.:smile:

it will be a normal english algorithm then. will it not be?:confused: but i think it will be little more technical, will be short, and will require careful thinking than normal english algorithm which i have written. tell me please is it so?

much grateful for helping me out.

cheers:smile:

What you have in the other thread is correct for what you need.

Just apply it here.
 
  • #16
okey-dokey. many thanks then.:smile:
 
  • #17
IMO the algorithm is NOT OK. My point about comparing five numbers is that you can really compare only two numbers at a time. For instance, to compare A and B you can check to see whether A > B, A == B, or A < B.

To find the largest of three numbers, A, B, and C, you're going to have to compare A with B, A with C, and B with C. My point is that you don't compare A, B, and C all in one operation. Your algorithm should go into some detail about exactly what you're going to do.
 
  • #18
Mark44 said:
IMO the algorithm is NOT OK. My point about comparing five numbers is that you can really compare only two numbers at a time. For instance, to compare A and B you can check to see whether A > B, A == B, or A < B.

To find the largest of three numbers, A, B, and C, you're going to have to compare A with B, A with C, and B with C. My point is that you don't compare A, B, and C all in one operation. Your algorithm should go into some detail about exactly what you're going to do.

I agree (well, exactly as per my example).

Bolded: As per post #13, my clause was it's ok but there does need to be more detail on the comparison.
 

Similar threads

Back
Top