// Exercise 04.01.03 // This program find the first prime number greater // than one billion (1000000000). // #include <iostream> #include <math.h> using namespace std; // Function must be declared before being used. int prime(int n); int main() { int i; // Set up an infinite loop; break if user enters 0. // Otherwise, evaluate n from prime-ness. for (i = 1000000000;; i++) { if (! prime(i)) { // Call prime(i) cout << i << " is not prime" << endl; break; } } return 0; } // Prime number function. Test divisors from // 2 to sqrt of n. Return false if a divisor // found; otherwise, return true. int prime(int n) { int i; double sqrt_n = sqrt(static_cast<double>(n)); for (i = 2; i <= sqrt_n; i++) { if (n % i == 0) // If i divides n evenly, return false; // n is not prime. } return true; // If no divisor found, n is prime. }

Just need somebody to explain this in deep...Eps the for loop in main. Thanks! Don't blame on me for asking stupid question. Sorry!