Results 1 to 5 of 5

Thread: regarding prime no.

  1. #1

    regarding prime no.

    plz send me the source code for finding whether a no. is prime or not


  2. #2
    Contributing Member
    Join Date
    Apr 2007
    Answers
    58

    Re: regarding prime no.

    int n,x,r;
    scanf("%d",&n);
    for (x=2;x<=n/2;x++)
    { r = n % x;
    if ( r!=0) break;
    }
    if ( r==0) printf("Prime");
    else printf("Not prime");

    Regards,
    Anoop :)
    If its useful, dont forget to [COLOR="Red"]THANK[/COLOR] me :cool:

  3. #3
    Junior Member
    Join Date
    Feb 2007
    Answers
    13

    Re: regarding prime no.

    Hi haltalk,

    I think the last 2 lines
    "if ( r==0) printf("Prime");
    else printf("Not prime");"

    should be like this:

    "if ( r==0) printf(" not Prime");
    else printf(" prime");"


  4. #4
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    Re: regarding prime no.

    Hi varun,

    I think you are studying in college. Try to use google search....You can get so much of results for these type of requirements...

    ---------------------
    suresh


  5. #5
    Contributing Member
    Join Date
    Apr 2007
    Answers
    58

    Re: regarding prime no.

    Hi Rpgubba, you are right. Anyway,sorry for the mistake, and the last lines should be like this as pointed out by rpgubba!

    "if ( r==0) printf(" not Prime");
    else printf(" prime");"

    Regards,
    Anoop :)
    If its useful, dont forget to [COLOR="Red"]THANK[/COLOR] me :cool:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact