Answer to Question #201451 in C++ for shubo

Question #201451
Given the following functions, What goes wrong when a main function makes a call to
displayRoot(5). Explain.
Make one change to the displayRoots() function to fix the problem and write the output.
#include <iostream>
using namespace std;
int k;
int funsqrt(int p)
{
k = 1;
while (k * k <= p)
{
k++;
}
return k-1;
}
void displayRoots(int p)
{
for (k = 0; k <= p; k++)
{
cout << funsqrt(k) << " ";
}
}
1
Expert's answer
2021-06-05T02:10:46-0400
#include <iostream>

using namespace std;

int k=1;

int funsqrt(int p)

{



while (k * k <= p)

{

k++;

}

return k-1;

}


void displayRoots(int p)

{

for (k = 0; k <= p; k++)

{

cout << funsqrt(k) << " ";

}

}
int main(){
displayRoots(5);
return 0;}


//it cant display because the function is displayRoots not displayRoot.for it to work both the function and function call must be the same
// Non-incremental error to solve.initialize k oustside

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog