Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //input number and precision places -> output square root using brute force
- #include<stdio.h>
- #include<string.h>
- typedef long double LD;
- int main()
- {
- LD a = 0, adder = 0.1;
- int n, p = 0;
- char format[99] = {0};
- scanf_s("%d%d", &n, &p);
- strcat_s(format, 99, "\n%");
- sprintf_s(format + 2, 97, ".%d", p);
- strcat_s(format, 99, "lf");
- while (p-- > 0)adder /= 10;
- while ((a * a) < (LD)n)a += adder;
- printf(format, a);
- return 0;
- }
Add Comment
Please, Sign In to add comment