a) Perform a DRY RUN on the algorithm below using the data provided. Lay out the results of the dry run in
TABLE FORMAT with a column for each variable.
Input A
C = 0
D = A
Repeat
Input B
If B > D
D = B
endif
C = C + 1
Until B = 0
Print D, B, C
DATA: 4, 6, 3, 7, 8, 5, 3, 9, 2, 0, 5, 1
The table headers should show each variable and the condition(s) being tested. Show the value of each
variable as it changes.
b) Describe the purpose of the program.
c) Would the final output be different if the first data input was changed to 7 instead of 4?
d) What would be the final value of D if the 9 in the list was replaced with 0?

OK, so that's your homework. What part of it are you having a problem with?

It's not too difficult. The instructions are pretty clear.
It might help you to understand the algorithm if you indent the pseudo-code in the same way that you would indent C++ code:

Input A
C = 0
D = A

Repeat
  Input B
  If B > D
    D = B
  endif
  C = C + 1
Until B = 0

Print D, B, C

And this DATA: 4, 6, 3, 7, 8, 5, 3, 9, 2, 0, 5, 1 must be the list of all values fed to the Input statements for a single run-through of the algorithm.

So, for part a) of your homework you simply need to make a table of all of the variables and their state/value at each step of the algorithm. You have four variables A, B, C and D.

So for the first statement in the algorithm Input A; according to the list of inputs (DATA:) the value will be 4, so A=4, B,C and D are undefined. So put that into your table against the first statement.

Then you move to the next statement in the algorithm and log the value of all four variables and continue until you have reached the end of the algorithm. Go through the loop as many times as required by the algorithm. Each time you reach an Input statement in the algorithm, record the next value in DATA against the appropriate variable in your table.

So for each step in the algorithm, you simply record the states of all four variables in a table and then determine what will be output at the end.

After that, parts b), c) and d) pretty much speak for themselves!
For part b): After the initial dry-run with the data provided, you should be able to deduce what the algorithms overall purpose is (if you can't already see it in the algorithm).
For parts c) and d): if you are unsure what the results will be, do a couple more dry-runs using the substituted values, record the values at each step and see what happens!

can you make this more easier please jason i would appreciate it thanks

I don't think I could make it any easier without actually doing your homework for you. And let's make this clear: I'm NOT going to do your homework for you. That's not what Daniweb is about! The community here exists to help guide you, not do your homework for you.

Please see the community rules, particularly this one from the 'Keep It Organized' section which states:

Do provide evidence of having done some work yourself if posting questions from school or work assignments

From what can be seen in this thread so far, you have made no attempt to do any of this yourself. I have already explained what you need to do as clearly and as simply as I can.

If you have a problem understanding anything about your homework questions, or anything that I or another user have presented to you, then please ask specific questions about the things you do not understand and one or more of us here will attempt to answer your questions.

So which part/parts of your homework do you not understand?

can you please dry run this?

    #include <iostream>
    using namespace std;
    int sum(int data[], int n);  //PROTOTYPE

    void main() 
    {
        int a[] = { 11, 33, 55, 77 }; 
        int size = sizeof(a)/sizeof(int); 
        cout << "sum(a,size) = " << sum(a,size) << endl; 
    }


    int sum(int data[], int n) 
    { 
        int sum=0; 
        for (int i=0; i<n;i++)
            sum += data[i];
        return sum;

}

If you have a question related to an existing post, you should create a new question and reference the other post with a link.If you have a question related to another post, you should create a new question and reference the other post with a link.

I found it complicated..!! isn't there more easier solution for this.??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.