c code function for computing ⌊√n⌋ for any +ve integer.

  • c
  • write a c code function for computing ⌊√n⌋ for any +ve integer.

    Write a program using a function for computing ⌊√n⌋ for any positive integer. Besides assignment and comparison, your algorithm may only use the four basic arithmetic operations. Hints: In number theory, the integer square root (sqrt) of a positive integer n is the positive integer m which is the greatest integer less than or equal to the square root of n, sqrt(n)=⌊√n⌋

    Code

    #include <stdio.h> #include <stdlib.h> #include <string.h> int isqrt(int n) { int i; for (i = 1; i * i <= n; i++) { } return i - 1; } int main() { int n; printf("Enter the number to find square root : "); scanf("%d", &n); printf("square root is : %d", isqrt(n)); return 0; }