1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

C++

Discussion in 'Software Development' started by jacy, Jan 12, 2006.

Thread Status:
Not open for further replies.
Advertisement
  1. jacy

    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;
    }
     
  2. AGCurry

    AGCurry

    Joined:
    Jun 15, 2005
    Messages:
    431
    It's not clear from your code exactly what you want your program to do.
     
  3. aewarnick

    aewarnick

    Joined:
    Sep 3, 2002
    Messages:
    828
    You may want to search the net for prime number c++ code to see what others have done.
     
  4. jacy

    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.
     
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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/433394

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice