Computer Science, asked by christina4545, 9 months ago

if x= -99 ;
calculate Math-sqrt (x);
In x-90
calculate math.sqrt(x);​

Answers

Answered by Anonymous
3

Answer:

// CPP program to find smallest value of root

// of an equation under given constraints.

#include <bits/stdc++.h>

using namespace std;

// function to check if the sum of digits is

// equal to the summation assumed

bool check(long long a, long long b)

{

long long int c = 0;

// calculate the sum of digit

while (a != 0) {

c = c + a % 10;

a = a / 10;

}

return (c == b);

}

// function to find the largest root possible.

long long root(long long n)

{

bool found = 0;

long long mx = 1e18;

// iterate for all possible sum of digits.

for (long long i = 0; i <= 90; i++) {

// check if discriminent is a perfect square.

long long s = i * i + 4 * n;

long long sq = sqrt(s);

// check if discriminent is a perfect square and

// if it as perefect root of the equation

if (sq * sq == s && check((sq - i) / 2, i)) {

found = 1;

mx = min(mx, (sq - i) / 2);

}

}

// function returns answer

if (found)

return mx;

else

return -1;

}

// driver program to check the above function

int main()

{

long long n = 110;

cout << root(n);

}

Similar questions