Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Another Prime Number Project - Medium

Here are some projects of actual programs you can practice making.

Another Prime Number Project - Medium

Postby programmattic on Thu Nov 05, 2009 10:02 pm

This program should do the following:

1-Have the user input a number.
2-Output whether or not the number is a prime.

HINT- Think of divisibility of the number by anything.

Here's my model of the program:

Code: Select all
#include <iostream>
   
using namespace std;
   
int main(){
   
   long int number;
   cout << "This is a program that tells whether a number is prime or not." << endl;
   cout << "Enter the number: ";
   cin >> number;

   for (long int i = 2;i < number;i++) {
   
      long int test = number % i;

      if (test == 0) {
         cout << "This number is not a prime number." << endl;
         break;
      } else {
         if (i == number - 1 && test != 0) {
            cout << "This number is a prime number." << endl;
         } else {
         continue;
         }
      }
      
   }

   system("pause");
   return 0;
}   


Good luck.
programmattic
 
Posts: 8
Joined: Sun Oct 18, 2009 5:02 pm

Re: Another Prime Number Project - Medium

Postby glinka57 on Fri Nov 06, 2009 6:23 pm

I wrote half a paragraph but halfway through making a version I realized it weas the exact same as yours lol, I'll work on one later.
nice work
User avatar
glinka57
 
Posts: 178
Joined: Fri Feb 27, 2009 7:32 pm


Return to Projects

Who is online

Users browsing this forum: No registered users and 0 guests

cron