Yahoo Interview Question for Software Engineer / Developers






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

/*A suggested solution,check it if wrong, comment on it*/
#include<stdio.h>
#include<conio.h>
int prime(int);
int main()
{int n,next;
clrscr();
printf("enter a given prime no:\n");
scanf("%d",&n);
next=prime(n);
printf("\nNext prime is:%d",next);
}
int prime(int x)
{int a=x+1,flag=0;
for(int i=2;i<=x;i++)
for( int j=2;j<=x;j++)
{ if(a%j==0)
{
a=a+1;
continue;
}
}
return(a);
}

- braj September 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

not able to understand... can u pl explain?

- Anonymous December 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes you are wrong braj.

- djebel January 18, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*A suggested solution,check it if wrong, comment on it*/

#include<stdio.h>

int prime(int);
int main() {
  int n, next;
  printf("enter a given prime no:\n");
  scanf("%d", &n);
  next = prime(n);
  printf("\nNext prime is:%d", next);
}

int prime(int x) {
  int a=x+1, flag=0;
  for (int i=2; i<=x; i++)
    for ( int j=2; j<=x; j++) {
      if (a%j == 0) {
        a = a + 1;
        continue;
      }
    }
  return a;
}

- Formatted Braj -- probably incorrect still! May 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*---------------------To find next prime no in java --------------*/
public class NextPrime {

boolean flag=true;
int i=1;int next = 0;
while(flag!=false)
{
next=n+i;
if(next==2)
{
flag=false;
break;
}
if(next%2==0)
{
flag=true;

}
else
{
flag=false;
}
i++;
}
System.out.println("Next Prime Number is :"+next);


}

public static void main(String[] args) throws NumberFormatException, IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter the number : ");
int number=Integer.parseInt(br.readLine());
NextPrime p=new NextPrime();
p.nextPrime(number);
}

}

- Ashok Singh October 17, 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