Exact square root
#include <iostream> using namespace std; int main() { int num, sqr,i; float temp, temp1,temp2; cout<<"Enter the no: "; cin>>num; for(i=1;i<num/2;i++){ sqr=i*i; if(sqr==num){ cout<<"Square root of "<<num<<" is "<<i; break; } if(sqr>num){ i=i-1; //temp2=(2*i); //temp1=(num-i*i); // temp=i+ temp1 /temp2; temp=i+(num-i*i)/(2*i); cout<<"Square root of "<<num<<" is "<<temp ; break; } } return 0; } Problem here is that if I will use temp1 and temp2 in temp then it return exact square root of any number but if I run temp without using temp1 and temp2 then it doesn't return exact value . Then exactly where is the problem