## 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;
}``````

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);
}
}``````

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;
}

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);
}``````

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);
}

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;

}

Comment hidden because of low score. Click to expand.
-2
of 2 vote

I think it is a definitely easy problem.

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.

### 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.