Jump to content
xisto Community

lalhsboard

Members
  • Content Count

    2
  • Joined

  • Last visited

Everything posted by lalhsboard

  1. I've been interested in learning C++ lately. I used to program in BASIC, but I've recently decided that I would begin to learn a more challenging language. I read online tutorials, and bought a book. Using only very basic C++, I wrote a one-file program that generates higher and higher prime numbers. I was always interested in how high prime numbers would get before they became very scarce. My program tries to generate prime numbers with maximum efficiency. It uses test division on a constantly increasing integer to determine if it is prime or not, and spits out the ones that test to be truly prime. It only tests odd numbers, and therefore only has to test divide by odd numbers. It also numbers the primes. I'll post the source here. Any feedback is appreciated, but remember: I'm just a beginner. #include <iostream>int testForPrime (int n) { int p, i; p = 1; i = 3; int result = n; while (i < result) { result = n / i; if (n == i * result) { p = 0; i = n; } i = i + 2; } return (p);}int main (int argc, char * const argv[]) { int p, i, n; i = 3; n = 5; std::cout << "Initiating prime number generation sequence...\n\n1: 2\n2: 3\n"; while (1) { p = testForPrime (n); if (p == 1) { std::cout << i << ": " << n << "\n"; i++; } n = n + 2; } return 0;}
  2. Anybody know what version of MySQL Xisto uses? 3.x? 4.x?
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.