Ask Question

Assume there is a variable, h already associated with a positive integer value. Write the code necessary to compute the sum of the perfect squares whose value is less than h, starting with 1. (A perfect square is an integer like 9, 16, 25, 36 that is equal to the square of another integer (in this case 3*3, 4*4, 5*5, 6*6 respectively).) Associate the sum you compute with the variable q. For example, if h is 19, you would assign 30 to q because the perfect squares (starting with 1) that are less than h are: 1, 4, 9, 16 and 30

+2
Answers (1)
  1. 5 November, 19:33
    0
    int i=1 / / initialized i to 1

    int q=0 / / initialized q to 10

    while ((i*i)
    {

    q = (i*i) + q / / calculating the sum of square

    i=i+1 / /Increment of i

    }

    Explanation:

    Following are the description of Program

    Initialized the variable "i" which is "int" type to 1. Initialized the variable "q" which is "int" type to 0. Iterating the while loop to less then variable "h". In this loop we calculate the sum of square and holding the result in the variable "q". Finally increment the value to "i" by 1 to iterating the loop.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Assume there is a variable, h already associated with a positive integer value. Write the code necessary to compute the sum of the perfect ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers