Pergunta de entrevista da empresa Microsoft

Write a program to print out the first n primes.

Respostas da entrevista

Sigiloso

7 de jul. de 2015

Can you explain your logic? I tried your program in C++, and it even prints 21 and 27 as prime numbers. This is my code, where fmod is a function that calculated the modulus result of 2 decimals (double). int main(){ int n; cin>>n; if(n==0){ return 0; } if(n>=1){ cout1){ if(fmod(x,sqrt(x))!=0){ cout<

1

Sigiloso

1 de jun. de 2020

The key in generic questions like this, is to make sure to cover the fundamentals. There's usually a back-and-forth with the interviewer. Might be worth doing a mock interview with one of the Microsoft Program Manager Intern experts on Prepfully? Really helps to get some real-world practice and guidance. prepfully.com/practice-interviews

Sigiloso

21 de mar. de 2014

public static void printNPrimes(int n){ if(n==0){ return; } if(n>1){ System.out.println(2); int x=3; while(n>0){ if(x%Math.sqrt(x)!=0){ System.out.println(x); } x=x+2; n--; } } }

Sigiloso

21 de mar. de 2014

Fixed. public static void printNPrimes(int n){ if(n==0){ return; } if(n>=1){ System.out.println(2); int x=3; while(n>1){ if(x%Math.sqrt(x)!=0){ System.out.println(x); } x=x+2; n--; } } }