1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Pseudocodes help

  1. Mar 31, 2016 #1
    1. The problem statement, all variables and given/known data
    1.Rewrite this algorithm using a repeat until loop and then with a while loop.

    Start
    sum=0
    Display "Input value n"
    Input n
    FOR( i=1 , i <=n , i+1 )
    Input a value
    sum=sum+value
    ENDFOR
    Output sum
    Stop

    I have some doubts if i have done the pseudo codes correctly.
    2.Design an algorithm for finding the sum of the numbers 2,4,6,8,...,n
    Can someone give me a leading clue on how to do it.
    3.Write an algorithm to read 100 numbers then display the largest.
    I am stuck midway.
    2. Relevant equations
    FOR( starting state , stopping condition, increment)
    3. The attempt at a solution

    Repeat until loop

    Start
    Repeat
    sum=0
    i=1
    Display "Input value n"
    Input n
    Display "Input a value"
    Input a value
    sum=sum+value
    i=i+1
    UNTIL n>=i
    Output sum
    Stop

    while loop.
    Start
    WHILE(n <>i)
    sum=0
    i=1
    Display "Input value n"
    Input n
    Display "Input a value"
    Input a value
    sum=sum+value
    i=i+1
    ENDWHILE
    Output sum
    Stop

    3.
    START
    count=0
    sum=0
    Input number
    For( c=1 , c>100 , c+1)
    sum=sum+value
    ENDFOR
    Output sum
    Stop
     
  2. jcsd
  3. Mar 31, 2016 #2
    Please put code (even pseudocode) inside of code tags makes it easier to read :)

    Let me ask some questions:
    1 (Repeat until): How does your code know where to "jump" back up to??

    1 (while): When the code gets to the ENDWHILE and returns to the While <> i what gets reexecuted?
    also the <> i is "NOT EQUAL TO" using it here isn't strictly wrong. But while n > i is safer. What would happen if the code accidentally jumped over n=i?


    2: There are strong similarities to previous problems. This time you know already what values your going to sum up...

    3: You're missing a way for the user to input a number. Also are you summing the values? or maybe you should just track something?
     
  4. Apr 1, 2016 #3
    1. ( Repeat until ) Since the until condition will still be false , it will go back up and repeats itself.
    1. I think it will re execute the sum =0 , i = 1 , so i should put those two at the top and the while <>i after
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Pseudocodes help
  1. Pseudocode Help (Replies: 1)

  2. Pseudocode help (Replies: 0)

Loading...