Summation questions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NewYorker
    New Member
    • Sep 2006
    • 13

    Summation questions

    PLEASE PLEASE PLEASE HELP ME ... I AM SO CONFUSED

    Q1:
    Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the non-negative values into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0.

    _______________ _______________ _______________ _______________ ____


    Q2:
    Assume the int variables i , lo , hi , and result have been declared and that lo and hi have been initialized.
    Write a for loop that adds the integers between lo and hi (inclusive), and stores the result in result .
    Your code should not change the values of lo and hi . Also, do not declare any additional variables -- use only i , lo , hi , and result .

    _______________ _______________ _______________ _______________ ____

    Q3:
    Given int variables k and total that have already been declared, use a while loop to compute the sum of the squares of the first 50 whole numbers, and store this value in total . Thus your code should put 1*1 + 2*2 + 3*3 +... + 49*49 + 50*50 into total . Use no variables other than k and total .

    _______________ _______________ _______________ _______________ ____

    Q4:
    Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared, use a while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total . Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total . Use no variables other than n , k , and total .
    _______________ _______________ _______________ _______________ ____

    Q5:
    Assume the int variables i and result , have been declared but not initialized. Write a for loop header -- i.e. something of the form
    for (* . * . * . * )
    for the following loop body:
    result = result * i;
    When the loop terminates, result should hold the product of the odd numbers between 10 and 20.
    NOTE: just write the for loop header; do not write the loop body itself.
  • Starasoris
    New Member
    • Oct 2006
    • 11

    #2
    Don't mean to be a spoiler, but which parts specifically don't you understand? It might help if you put in what you can already work out and relate your questions to that.

    When I was at school, they never actually gave us the questions before hand, or perhaps these are just examples.

    But please, throw in some code and we can explain what you don't understand or are missing.

    Comment

    • NewYorker
      New Member
      • Sep 2006
      • 13

      #3
      these Are Given As Exam Preparation ... Can Anybody Help ..?

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        You should attempt these yourself first and post you code with the problems you are having.

        If you are unable to do this for any (or all) question because of you confusion then you should post saying what it is about each question that is confusing you.

        Tackle them 1 question at a time, do 1 first, while you are doing 1 do not consider the other questions.

        Comment

        Working...