Ask Question
18 January, 16:01

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

+3
Answers (1)
  1. 18 January, 17:40
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers