employer cover photo
employer logo
employer logo

National Security Agency

Engaged employer

National Security Agency interview question

Write a simple function that prints out all factors of a given number n.

Interview Answers

Anonymous

10 Jan 2019

for (int i = 1; i <= n; i++) { if (n % i == 0) then print out i }

2

Anonymous

24 May 2020

#include int main() { using namespace std; try { int product = 0; cout > product; for (int i = 1; i <= product; i++) { if (product % i == 0) { cout << i << " is a factor of " << product << endl; } } } catch (exception &ex) { cout << ex.what() << " in main." << endl; return EXIT_FAILURE; } return EXIT_SUCCESS; }