Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ Assume we’ve already declared and initialized a variable called val to ho

ID: 3785553 • Letter: I

Question

In C++

Assume we’ve already declared and initialized a variable called val to hold some positive

integer. The following code is supposed to print “true” if val has an integer square root

and “false” otherwise. Which line should replace the comment?

int count = 0;

//which line goes here?

       count++;

if (count * count == val)

       cout << “true” << endl;

else

       cout << “false” << endl;

Answer

a) while (count * count <=val)

b) while (count * count <val)

c) while (count * count !=val)

Explanation / Answer

#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{

int count = 0;
int val=0;
while (count * count <=val)
{

count++;
if (count * count !=val)
{

cout<<"true"<<endl;
}
else
{

cout<<"false"<<endl;
}
}

return 0;  
}

output

true

ans)while(count*count!=val)