Epic Systems Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
3
of 3 vote

probably a binary search would also work
for ex
2<sqrt(8)<3;
now try 2.5 since 2.5*2.5=6.25 so try betwen 2.5 and 3 and so on

- Anonymous November 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

use rahsonmethod
float x1=num,x2=0;
x2=.5*(x1+num/x1);
while((x1-x2)!=0)
{
x1=x2;
x2=.5*(x1+num/x1);
}
cout<<x2;

- darklord sharad kumar September 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Super!

- Anonymous January 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Newton - Rahson Method Implementation:

import java.util.Scanner;

public class Squareroot 
{

	public static void main(String[] args) 
	{
		System.out.println("Please enter a number to find the squareroot");
		Scanner scan = new Scanner(System.in);
		double num =Integer.parseInt(scan.next());
		double x= num;
		double y = (0.5)*(x +(num/x));
		while(x!=y)
		{
			x = y;
			y= (0.5)*(x +(num/x));
		}
		System.out.println("Final squareroot of "+num+" ----> "+y);

	}

}

- GKR March 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

public static void SquareRoot(int n)
        {
            float guess = 1;
            float number = (float)n;
            while (Math.Abs((number / guess) - guess) > 0.001f)
            {
                guess = (guess + (number / guess)) / 2;
            }
            Console.WriteLine("Square Root of " + n + ": " + guess);
        }

- Anonymous November 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

stupid algo..
first of all u take int n when it should be a float !!

also take n=100
guess = 1
guess = (guess + number/guess)/2 => 51 !!

dumbass

- ~ December 14, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

dumbass....stop playing with people's careers !!!
by posting this shit.
Only post code which works and gives the *correct* answers.
I don't think it's that tough to understand is it?

- Anonymous May 02, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

find an integer i, such that i*i < float < (i+1)*(i+1)
then, denote x = (f-i*i)/(i*i)
sqrt(f) = i* (1+x)^0.5
then Taylor series.

From a mathematical point of view.

- geniusxsy September 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

you can also do it as if you are solving an equation:
x^2 - f = 0;

using either Newton's recursive method;

- Anonymous September 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void prob6()
{
	float input;
	cout<<"Input a non-negative float number!"<<endl;
	cin>>input;
	while(input<0) //if it is negative, re-input
	{
		cin>>input;
	}

	//Find an initial point x0, such that x0^2>input and x0 is minimal
	int i=0;
	while(true)
	{
		if(i*i>input)
			break;
		i++;
	}

	float x_0=(float)i;
	float x_1;
	float error=0.01f;
	float diff;
	while(true)
	{
		x_1=x_0-(x_0*x_0-input)/(2*x_0);
		diff=x_1*x_1-input;
		if((diff<error)||(diff>-error))
		   break;
		else
		   x_0=x_1;
		
	}

	cout<<"The approximate (Error<="<<error<<")square-root is:"<<x_1<<endl;
}

- Anonymous October 22, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

double (int num,int tol) //num = number,tol=tolerance value
{
double tmp=num,tmp2;
while(1)
{
tmp2=.5*(tmp+num/tmp);
if(tmp - tmp2 < tol)
{
return tmp2;
}
tmp=tmp2;
}
}

- try this..easy and best. March 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
using namespace std;

static double root;
static double diff;

void getroot(double num,double min, double max)
{
root=(min+max)/2;
diff=root*root-num;
if(0<=diff)
{
if(diff<0.001)
cout<<root;
else
{
max=root;
getroot(num,min,max);
}
}
else
{
min=root;
getroot(num,min,max);
}


}

int main(){
double num;

cout<<"please input the number:"<<endl;
cin>>num;
if(num<1)
getroot(num,num,1);
else
getroot(num,0,num);

}

- Anonymous May 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static double getSqrt(double x) {
double a = 1;
double b = 0;
while(true) {
b = 0.5 * (a + x/a);
if (a == b) break;
a = b;
}
//floating-precision of 4 decimal places
b = (double)(int)((b+0.00005)*10000.0)/10000.0;
return b;
}

- Professor May 25, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

double sqrt( int n )
{
	double a = (double) n;
	double x = 1;
 
	for( int i = 0; i < n; i++)
	{
		x = 0.5 * ( x+a / x );
	}
 
	return x;
}

- ~RaZoR~ February 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

const double epsilon = 0.00000000000000001;
double sqrt(const double x){
if (x < 0){
throw Exception("wrong input");
}

if (abs(x - 1) < epsilon)
return 1;

double left, mid, right;
if (x < 1){
left = x;
right = 1;
}
else{
left = 1;
right = x;
}
mid = (left + right)/2;

while (abs(mid * mid - x) > epsilon){
if (contains(left, mid, x)
right = mid;
else
left = mid;
mid = (left + right)/2;
}

return mid;

}

int contains(double left, double right, double key){
return (key >= left || key <= right)? 1: 0;
}

- css February 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
using namespace std;

/* Function declarations */
double mySqrt(double input);
/* Function definitions */
double mySqrt(double input)
{

double result=0.001;
while(result*result - input < 0.0 )
{
result+=0.001;
}
return result;
}

int main()
{
char key;
double result;
double input=5.67;
result=mySqrt(input);
cout<<result<<endl;
cin>>key;
return 0;
}

- hberus February 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey95907" class="run-this">public void square_root (float num) {
float n1 = 0f;
float n2 = 0f;

n1 = num/2;

/Newton-Raphson's method
while(n1 != n2) {
n1 = n2;
n1 = n2 + (((n2*n2) - num)/(2*n2));
}

System.out.println("Square root is " + n1);
}</pre><pre title="CodeMonkey95907" input="yes">
</pre>

- Anonymous July 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Help.......How to stop and make stable of this output....it keeps on giving output...

#include<stdio.h>
main()
{ int i,j,k=1;
long double a,num,n;
printf("Enter the no whose square root is to find\n");
scanf("%Lf",&n);
i=0;
while(i*i<n)
i++;
a=(double)i-1.000;
printf("\n i is %d, %Lf\n",i,a);
while(a*a<n+1)
{
if(a*a==n)
break;
else
{ if(a*a<n)
a=a+1/(pow(10,k));
else
{ a=a-1/(pow(10,k));
k++;
}
}
printf("The square root of %Lf is %Lf\n",n,a);
}
}

- @123 August 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

enum Status {kValid = 0, kInvalid};
int g_nStatus = kValid;
float sqrf(const float input)
{
g_nStatus = kInvalid;
double base = 0.0;
if(input >= 0){
float tryNum = 1.0;
int i = 0;
int count = 0;
while(i < 8)
{
count = 0;
float midResult = 0.0;
while(midResult < input)
{
base = base + tryNum;
midResult = base * base;
count ++;
}
base = base - tryNum;
tryNum = tryNum / 10.0;
i++;
}
base = base - count * 0.0000001;
if(count > 5);
base = base + 0.000001;
g_nStatus = kValid;
}
return (float)base;
}

- Encen February 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int sqrt(int x) {
    if(x<0) return -1;
    if(x==0) return 0;
    int l=1;
    int r=x/2+1;
    while(l<=r)
    {
        int m = (l+r)/2;
        if(m<=x/m && x/(m+1)<m+1)
            return m;
        if(x/m<m)
        {
            r = m-1;
        }
        else
        {
            l = m+1;
        }
    }
    return 0;
}

- sduwangtong October 28, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More