You are viewing a single comment's thread. Return to all comments →
int squareRoot(int number){ int result=0; int variable=1;
while(result<=number){ result=variable*variable; if(result>number){ // no need increment variable++ break; } variable++; } return variable-1;
}
int squares(int a, int b) { int lower=squareRoot(a); int upper=squareRoot(b); if(lower*lower==a){ //if a is perfect square, then decrement lower--; }
return (upper-lower);
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Squares
You are viewing a single comment's thread. Return to all comments →
int squareRoot(int number){ int result=0; int variable=1;
}
int squares(int a, int b) { int lower=squareRoot(a); int upper=squareRoot(b); if(lower*lower==a){ //if a is perfect square, then decrement lower--; }
}