NetApp Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

The easiest way of finding the GCD of two numbers is by using the Euclidean algorithm.

en.wikipedia.org/wiki/Euclidean_algorithm.

Code:
Recursive Code

public static int gcd(int a,int b){
		if(b==0)
			return a;
		else return gcd(b,a%b);
	}

Non-Recursive:

public static int gcd(int a,int b){
		while(b!=0){
			int t = a%b;
			a = b;
			b = t;
		}
		return a;
	}

- Coder January 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void gcd(unsigned long long a, unsigned long long b)
{
if(b==0) return a;
else
{
unsigned long long r = a%b;
gcd(b,r);
}
}

- archana February 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int gcd(int v1, int v2) {
while(v2) {
int temp = v2;
v2 = v1 % v2;
v1 = temp;
}
return v1;
}

- xiaobinly April 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int gcd(int a,int b)
{
	return (b==0)?a:gcd(b,a%b);
}

- Satish Patel June 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>

void main()
{
int num1, num2;
int div, rem,quot;
printf("\n Enter number 1 : \n");
scanf("%d",&num1);
printf("\n Enter number 2 : \n");
scanf("%d",&num2);

if(num1<num2)
{
quot=num1;
div=num2;
}
else
{
quot=num2;
div=num1;
}
rem=num1+num2;

while(rem)
{
rem=div%quot;
if(rem!=0)
{
div=quot;
quot=rem;
}
}
printf("\n GCF is is <%d> \n",quot);
}

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

#include <stdio.h>
int calculategcd(int first,int second)
{
int gcd=1,loop=0,i=0;
if(first ==0 || second ==0 )
return 0;

if(first==1|| second==1)
{
gcd=1;
return gcd;
}
if(first<second)
loop =first;
else
loop=second;
for(i=2;i<=loop;i++)
{
if((first%i==0)&&(second%i==0))
gcd=gcd*i;
}

return gcd;
}
int main()
{
int first =0,second=0,gcd =0;
scanf("%d %d",&first,&second );
gcd =calculategcd(first,second);
printf("GCD =%d",gcd);
getchar();
return 0;

}

- vinod dubey September 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

I think it is a definitely easy problem.

- ctang January 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