 # sqrt(a)+sqrt(b)=sqrt(2020)_v1.c

Sep 4th, 2020 (edited)
163
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /*
2.
3.     sqrt(a)+sqrt(b)=sqrt(2020)_v1.c
4.
6.     sqrt(a)+sqrt(b)=sqrt(2020)
7.     Find a and b.
8.
9.
10.     You can find all my C programs at Dragan Milicev's pastebin:
11.
12.     https://pastebin.com/u/dmilicev
13.
14. */
15.
16. #include <stdio.h>
17. #include <math.h>
18.
19. #define NUM_OF_ITERATIONS 1000
20.
21. int main(void)
22. {
23.     int a, b, number_of_solutions=0;
24.     double c = sqrt(2020);
25.
26.     for(a=1; a<NUM_OF_ITERATIONS; a++)
27.         for(b=1; b<NUM_OF_ITERATIONS; b++)
28.         {
29.             if( abs(c - sqrt(a) - sqrt(b))  < 0.1 )
30.             {
31.                 number_of_solutions++;
32.                 printf("\n a = %d \t b = %d \n", a, b );
33.                 printf(" \n %.16lf = sqrt(a) \n %.16lf = sqrt(b) \n  %.16lf = c-sqrt(a)-sqrt(b) \n", sqrt(a), sqrt(b), c - sqrt(a) - sqrt(b) );
34.             }
35.         }
36.
37.     if( number_of_solutions == 0 )
38.         printf("\n There is no such digits. \n");
39.     else
40.         printf("\n There are %d solutions. \n", number_of_solutions );
41.
42.     return 0;
43.
44. } // main()
45.
RAW Paste Data Copied