#include
using namespace std;
int main()
{
int n,k=1,sum=0;
cin>>n;
label:
for(int i=0;;i=i+k)
{
if((i*i)>n)
{
i=i-1;
sum=sum+i;
k=k/10;
if(k==0.01)
{
goto end;
}
else goto label;
}
}
end:
cout<<"\n"<<sum;
return 0;
}
Why im not getting square root being displayed..though theres no error
Hello @prerak_semwal this is the correct code:
there was some mistake by you when you are checking k==0 there you should have done k==0 but you were doing k==0.01 .
and that condition will never be there thats why it was giving segmentation fault.
Happy Learning!!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.