Thread: emirps program help

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    37

    emirps program help

    i'm working on a program that is supposed to display the first 100 emirps. right now i have it so i have to put in an input.

    i need the program to run itself with no input .. and it has to display all the emirps like 10 per line ..

    here is my code right now .. it just diisplays if an inputted number is prime or not and it checks if its emirp is prime or not .. how can i adjust it to do what i mentioned above?

    Code:
    #include <iostream>
    using namespace std;
    
    enum Logical {False, True};
    
    int get_valid_number();
    Logical prime(int integer);
    int reverse_num(int sourcenum);
    	
    int main() 
    {
      int number, sum, counter;
    
      for (counter=1; counter<=600; counter++)
      {
    
      cout << "This will test to see if a number is prime...\n" << endl;
    
      number = get_valid_number();
      while (number != 0) {
        cout << "\n\nThe number " << number << " is ";
        if (!prime(number))
          cout << "not ";
        cout << "a prime number...\n\n";
      
    
      sum = reverse_num(number);
      cout << "Also the EMIRP, " << sum << " is ";
    	   if (!prime(sum))
    	     cout << "not ";
    	   cout << "a prime number...\n\n";
           number = get_valid_number();
      }
    
      return (0);
    }
    
    int get_valid_number() 
    {
      int number;
      do 
      {
        cout << "\nEnter an integer...(0 to end): ";		
        cin >> number;
      } 
      while (number < 0 || number > 10000);
    
      return number;
    }
    	
    
    Logical prime(int integer)
    {
      for (int factor = 2; factor<integer; factor++) {
        if ((integer % factor) == 0) 
          return False;
      }
      return True;
    }
    
    int reverse_num(int sourcenum)
    {
    	int temp = sourcenum;
    	int sum = 0;
    	while (temp)
    	{
    		sum*=10;
    		sum += temp%10;
    		temp/=10;
    	}
    	return sum;
    }

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    can't you just loop through all integers from 0 to 2^32-1 and perform the same test?

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM