Hi there. I have two algorithm problems.(adsbygoogle = window.adsbygoogle || []).push({});

I was wondering if you can check my answers for the first one and help me get a start with the second one:

1)Write an algorithm to compute the average of 5 numbers

Name: Ave5

Given: X1, X2, X3, X4, X5

Change: none

Intermediate: Total

Result: Average

Definition: Average:= Ave5 (X1, X2,X3,X4,X5)

METHOD

Get X1

Get X2

Get X3

Get X4

Get X5

Total = X1 + X2 + X3 + X4 + X5

Average = Total/5

Give Average

2) Write an algorithm to get the names and ages of two people. Return the name of the person who is older (in format "x is older than y", where x and y are the names of the two people), unless the two people are the same age, in which case, return the message "x is the same age as y.

I'm having trouble writing an algorithm for this particular case. It's more complicated than what I am used to. Can someone give me an idea on how to start a problem like this one ? I have made a couple of assumptions:

Name: PerAge

Givens: X, Y

Change: X,Y

Intermediate: Age

Result: none

Definition: Age =: PerAge (X,Y)

METHOD

Give X

Give Y

Well... I'm pretty lost at this point

Thank you advance

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Algorithm problem (please help)

Loading...

Similar Threads - Algorithm problem please | Date |
---|---|

C/++/# Is there a flaw in my longest common subsequence algorithm? | Feb 24, 2018 |

C/++/# Finding duplicates algorithm | Jan 20, 2018 |

Complexity Analysis problem of an Algorithm. | May 9, 2015 |

Problem in c++ in writing an algorithm | Nov 20, 2008 |

Problem with summation algorithm | Sep 29, 2007 |

**Physics Forums - The Fusion of Science and Community**