Program to find a square root

copy paste the code below and pls tell why i’/ not getting any output…sample INPUT = 25

#include<bits/stdc++.h>
using namespace std;
int main(){
int n,count=0;
float sum,k=1;
cin>>n;
for(float i=k;;++k){
if(ii == n){
cout<<i;
return 0;
}
else if((i
i)<n)
continue;
else {
sum+=i-k;
k/=10;
i=k;
count+=1;
}
if(count==4)
break;
}
cout<<sum;
return 0;
}

Hey @prerak_semwal share your code using ide.codingblocks.com as this is not a challenge question so i don’t have your submission. Go to ide.codingblocks.com paste your code there and then save it. A special url will be generated in your search bar, share that url with me.

The logic you are using to solve is not right, check this->


In your for loop, value of i is not incrementing. Thus giving you TLE. Try to do it like this.

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.