Results 1 to 4 of 4

Thread: Prime number

  1. #1
    Join Date
    Sep 2008
    Posts
    16

    Prime number

    I tried to make a program that will view the prime numbers from 1 to 100 but it seems that I have a problem in my code
    Code:
     
    #include <stdio.h> 
    #include <stdlib.h>
    
    int main () 
    {
    int r = 0; 
    int i, j; 
    printf ( "prime number: 2 \ n"); 
    for (i = 3; i <100; i + +) 
    {
    for (j = i - 1; j> 1; j -) 
             {  
                  i% r = j; 
                 if (r == 0) 
                 {  
                     i = i + 1; 
    
                 }
    
             } 
            printf ( "prime number:% ld \ n", i); 
         } 
    return 0; 
     }

  2. #2
    Join Date
    Jan 2008
    Posts
    56
    Good evening,

    In your condition, when you go to the next whole
    i = i + 1 also requires you reset I just like this after j = i - 1

    Note: your algorithm is far from being optimized, you could begin to initialize j by the root of i

  3. #3
    Join Date
    Aug 2008
    Posts
    38
    a prime number is a number that no number less than or equal to the square root not divides, and you do a loop for this test, and if the modulas is <> 0 then shows you the number, and that's all.
    passing you want helps you managed to solve by yourself or you want even a correction in this case I put the correct code, then the answer?

  4. #4
    stevejohnson Guest

    RE: prime number

    This is the forum where we can get the information about software programs.

    ____________________________________________

Similar Threads

  1. Problem with C# program which calculates the prime number
    By $Bird$ in forum Software Development
    Replies: 4
    Last Post: 29-11-2010, 12:54 PM
  2. Shell program for the prime number
    By Rup_me in forum Software Development
    Replies: 5
    Last Post: 14-12-2009, 10:24 AM
  3. program to check prime number in java
    By Bansi_WADIA in forum Software Development
    Replies: 3
    Last Post: 24-11-2009, 11:02 PM
  4. Prime Number programme in C#
    By Harshit in forum Software Development
    Replies: 2
    Last Post: 14-11-2008, 01:09 PM
  5. Check whether an integer is a prime number in C
    By Projectkmo in forum Software Development
    Replies: 2
    Last Post: 08-10-2008, 06:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,638,908.12915 seconds with 17 queries