127k views
1 vote
Assume there is a variable , h already associated with a positive integer value. Write the code necessary to count the number of 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).) Assign the sum you compute to a variable q For example, if h is 19 , you would assign 4 to q because there are perfect squares (starting with 1 ) that are less than h are: 1 , 4 , 9 , 16 .

_____________________________________________________________________________

1 Answer

3 votes

Answer:

pseudo code:

x=1

q=0

while x*x<h: {

x += 1}

q=x-1

complete code in C language

#include <stdio.h>

int main() {

int h=19;

int q=0;

int x=1;

while ((x*x)<h){

x += 1;

}

q=(x-1);

printf("The sum of total perfect squares less than %d is: %d", h,q);

return 0;

}

Step-by-step explanation:

first '%d' in print statement refers to h and second '%d' in print statement refers to q

User Rishabh Anand
by
5.1k points