Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

program to find prime number between 2 and any given integer and print

yak98yak98 Member Posts: 4
hi
i am new to c.i tried to write a program to find all prime numbers between 2 and any given number and print them.i am attaching the source code.but everytime i run it,garbage value appears.can anyone help me with it?

Comments

  • ishan_2kishan_2k Member Posts: 6
    hello, following is the program for finding prime number it also prints about other number are prime number or not. if you want to print only prime numbers just remove last printf statement of the program.and "is a prime number" in previous printf statement.
    i does not found your source now but yesterday i see it and there is a
    "&" in printf statement in while loop.


    #include
    main()
    {
    int check, i, x,y,m;
    printf("enter the number upto which check");
    scanf("%d",&check);
    y=1;
    for(m=2; m<=check; m++)
    {
    for(x=2;x<m; x++)
    { y=m%x;
    if(y==0)
    break;
    }
    if(y!=0)
    printf("%d is prime number
    ",m);
    else printf("%d is not a prime number
    ",m);
    }
    getch();
    }

  • ishan_2kishan_2k Member Posts: 6
    hello, following is the program for finding prime number it also prints about other number are prime number or not. if you want to print only prime numbers just remove last printf statement of the program.and "is a prime number" in previous printf statement.
    i does not found your source now but yesterday i see it and there is a
    "&" in printf statement in while loop.


    #include
    main()
    {
    int check, i, x,y,m;
    printf("enter the number upto which check");
    scanf("%d",&check);
    y=1;
    for(m=2; m<=check; m++)
    {
    for(x=2;x<m; x++)
    { y=m%x;
    if(y==0)
    break;
    }
    if(y!=0)
    printf("%d is prime number
    ",m);
    else printf("%d is not a prime number
    ",m);
    }
    getch();
    }

  • ishan_2kishan_2k Member Posts: 6
    hello, following is the program for finding prime number it also prints about other number are prime number or not. if you want to print only prime numbers just remove last printf statement of the program.and "is a prime number" in previous printf statement.
    i does not found your source now but yesterday i see it and there is a
    "&" in printf statement in while loop.


    #include
    main()
    {
    int check, i, x,y,m;
    printf("enter the number upto which check");
    scanf("%d",&check);
    y=1;
    for(m=2; m<=check; m++)
    {
    for(x=2;x<m; x++)
    { y=m%x;
    if(y==0)
    break;
    }
    if(y!=0)
    printf("%d is prime number
    ",m);
    else printf("%d is not a prime number
    ",m);
    }
    getch();
    }

  • globalprogglobalprog Member Posts: 67
Sign In or Register to comment.