KAR98S

squareRoot using bruteForce.c

Jan 28th, 2021 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. //input number and precision places -> output square root using brute force
  2. #include<stdio.h>
  3. #include<string.h>
  4. typedef long double LD;
  5.  
  6. int main()
  7. {
  8.     LD a = 0, adder = 0.1;
  9.     int n, p = 0;
  10.     char format[99] = {0};
  11.     scanf_s("%d%d", &n, &p);
  12.     strcat_s(format, 99, "\n%");
  13.     sprintf_s(format + 2, 97, ".%d", p);
  14.     strcat_s(format, 99, "lf");
  15.     while (p-- > 0)adder /= 10;
  16.     while ((a * a) < (LD)n)a += adder;
  17.     printf(format, a);
  18.     return 0;
  19. }
Add Comment
Please, Sign In to add comment