List of practical programmes in C Language for M. Tech / M.C.A., / B.E./ B.Tech./ Computer Science / B.Sc. / BCA PRACTICAL PROGRAMMING & PROBLEM SOLVING THROUGH C - I / II
#include
int main()
{
int number;
float temp_var, square_root;
printf("Enter the number, whose square root is required : \n");
scanf("%d", &number); // say number = 16
// divide the number by half and store it into the square_root
square_root = number / 2; // our given number = 16 , then half of 16 is 8, and stored into square_root
temp_root = 0; // initiallized by zero
// Repeat the steps until square_root and temp_var are not equal
while(square_root != temp_var){
// initially square_root = 8 ; temp_var =0
// (on second iteration = 5)
// and so on
temp_var = square_root;
// Then, replace values (16 / 8 + 8 ) / 2 = 5
// (on second iteration 5)
// and so on
square_root = ( number/temp_var + temp_var) / 2;
}
printf("The square root of '%d' is '%f'", number, square_root);
return 0;
}