Thread: Help with a program.thanks in advance.

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    16

    Help with a program.thanks in advance.

    Code:
    #include<stdio.h>
    
    int main()
    {
        int x,y;
    for(y=1;y<=1000;y=y+1){
        x=y;
    if(x==1 || x==2 || x==3 || x==5 || x==7 || x==11)
    {printf("\nprime%d",x);}
    
    else if(x%2==0 || x%3==0 || x%5==0 || x%7==0 || x%11==0)
    {printf("\nnot prime%d",x);}
    
    else
    {
        printf("\nprime%d",x);
    }
    }
    }

    this program should start from 1 and then print all numbers and define the properties(prime or not) of that number.But the number is starting from 704(or something) But not from 1.

    if i start it from 1 and end before 100 it works fine..

    i have debugged it.no problem shown.

    IT all works fine.

    but what is the problem with the output?why it starts from 700???

    please compile and debug it.

    thanks

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    What does your program output when y is equal to 169?

  3. #3
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Quote Originally Posted by DeadPlanet View Post
    What does your program output when y is equal to 169?
    It will be prime, you can run the program.

    May be on your console you can check from 700 or something, your program is displaying prime/nor prime from 1 to 1000

  4. #4
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Quote Originally Posted by RockyMarrone View Post
    It will be prime, you can run the program.
    And you don't see a problem with 13*13 being prime?

    I'd rather you didn't answer the questions that I pose to the OP to make them think about the errors in their program.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Quote Originally Posted by DeadPlanet View Post
    And you don't see a problem with 13*13 being prime?

    I'd rather you didn't answer the questions that I pose to the OP to make them think about the errors in their program.
    "What does your program output when y is equal to 169?" replied run the program because program was running...

    And about another one, this website doesn't owned by you, so where I need to comment and answer I don't have to take your permission.

  6. #6
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    "What does your program output when y is equal to 169?" replied run the program because program was running...
    I don't understand what you mean by this.

    And about another one, this website doesn't owned by you, so where I need to comment and answer I don't have to take your permission.
    This statement is 100% correct.

  7. #7
    Registered User
    Join Date
    Jan 2012
    Posts
    16
    guys i just have problem that why isnt the program displaying all results???using codeblock

  8. #8
    Registered User
    Join Date
    Jan 2012
    Posts
    16
    and the program doesnt work.thanks for pointing out the mistake

  9. #9
    Registered User
    Join Date
    Apr 2011
    Location
    dust
    Posts
    70
    check till 100!!
    I mean execute the for loop till 100 only and checks the output

  10. #10
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    You are problably running out of console space if it starts that high, just a thought try making the loop go to 50 and see if it starts from the beginning.

  11. #11
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    redirect your output to a file or pipe it to 'more' to see if initial results are flying off the screen

  12. #12
    Dweeb dojha00's Avatar
    Join Date
    Feb 2012
    Location
    Global
    Posts
    23
    I have compiled this program in Ubuntu10.10 and it's working.means no execution problem and output starting from 1 and goes on...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 02-01-2012, 09:32 AM
  2. Introduction and Thanks in Advance!
    By Gallaton in forum C++ Programming
    Replies: 3
    Last Post: 05-12-2009, 12:37 AM
  3. Help w/C++ program.. thanks in advance.
    By patricio2626 in forum C++ Programming
    Replies: 4
    Last Post: 10-15-2006, 08:06 AM
  4. need some help thanks in advance
    By Mshock in forum C Programming
    Replies: 7
    Last Post: 05-07-2006, 06:44 AM
  5. thanks in advance
    By vijayalakshmi in forum C Programming
    Replies: 32
    Last Post: 02-24-2005, 04:38 PM