C++

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

jacy

Thread Starter
Joined
Jul 19, 2004
Messages
120
Hi,
Is there an effective way of writing the prime number programm that i wrote, thanks. I am using Dev C++.


#include <iostream>
using namespace std;
int main ()
{
int i;
int num;
i=2;
cout<<"enter a number ";
cin>> num;
while (num>=i)
{
getchar ();
if (num == i)
{
cout<<"prime number";
getchar ();
break;
}
if ((num%i)==0)
{

cout<<num<<"is not a prime number";
getchar();
break;
}
else
{
i++;
if ((num%i)==0)
{
cout<<num<<"is not a prime number";
getchar();
break;
}
else
{
cout<<num<<"is a prime number";
getchar ();
break;
}
}
i++;
}
return 0;
}
 
Joined
Sep 3, 2002
Messages
828
You may want to search the net for prime number c++ code to see what others have done.
 

jacy

Thread Starter
Joined
Jul 19, 2004
Messages
120
Sorry that my code is not clear. I am trying to find out whether the number entered by the user is prime number or not. Thanks.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top