| | |
Algorithm problem
Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
![]() |
•
•
Join Date: Oct 2005
Posts: 1
Reputation:
Solved Threads: 0
Hi there. I'm Kurt!!
I have two algorithm problems.
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
I have two algorithm problems.
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
>I was wondering if you can check my answers for the first one and help me get a start with the second one
The first one looks fine. Your problems with the second one makes me wonder.
>It's more complicated than what I am used to.
So basically anything that has more than one branch of execution is too much for you. You're looking at three branches: the ages are equal, x is less than y, and x is greater than y. Do you know how to use an if..else?
The first one looks fine. Your problems with the second one makes me wonder.
>It's more complicated than what I am used to.
So basically anything that has more than one branch of execution is too much for you. You're looking at three branches: the ages are equal, x is less than y, and x is greater than y. Do you know how to use an if..else?
New members chased away this month: 4
![]() |
Similar Threads
- help writing pseudocode, PLEASE!!!! (C++)
- dijkstra algorithm problem in c++ (C++)
- algorithm problem with recursion (Java)
- recursive algorithm (C++)
- algorithm performance measure (Computer Science)
- I need advices for the Pseudocode (JavaScript / DHTML / AJAX)
- 2038 Problem (C++)
- weighted graph (Computer Science)
Other Threads in the Computer Science Forum
- Previous Thread: help finding a recurrent relation, Discrete Math
- Next Thread: basic matlab question
| Thread Tools | Search this Thread |
Tag cloud for Computer Science
ai algorithm algorithms amazon assignment assignmenthelp assignments automata battery bigbrother binary bittorrent bizarre bletchleypark blogging business cern clueless compiler computer computers computerscience computertrackingsoftware connect conversion csc data dataanalysis development dfa dissertations dissertationthesis dissertationtopic ebook employment energy floatingpoint foreclosuresoftware fuel gadgets geeks givemetehcodez government graphics hardware history homework homeworkassignment humor ibm idea ideas internet iphone ipod itcontracts jobs kindle laser lazy linkbait lsmeans marketing mining mobileapplication msaccess netbeans networking news os p2p parser piracy principles programming rasterizer research science security sex simulation software spoonfeeding spying stephenfry student study supercomputing sweden syntactic technology textfield tree turing turingtest two'scompliment uk virus warehouse ww2






