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

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 Posts: 4Member
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 Posts: 6Member
    : 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?
    :
    hello following is the source code for printing the number is prime or not if you want to only print prime number just delete last printf statement after else and also "is aprime number" from its previous printf statement. i am not able to see your source code now but yesterday see it and the is a "&" in printf statement in your while loop.

    source code:
    #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();
    }
    Regards:ishan_2k

  • ishan_2kishan_2k Posts: 6Member
    : 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?
    :
    hello following is the source code for printing the number is prime or not if you want to only print prime number just delete last printf statement after else and also "is aprime number" from its previous printf statement. i am not able to see your source code now but yesterday see it and the is a "&" in printf statement in your while loop.

    source code:
    #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();
    }
    Regards:ishan_2k

  • ishan_2kishan_2k Posts: 6Member
    : 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?
    :
    hello following is the source code for printing the number is prime or not if you want to only print prime number just delete last printf statement after else and also "is aprime number" from its previous printf statement. i am not able to see your source code now but yesterday see it and the is a "&" in printf statement in your while loop.

    source code:
    #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();
    }
    Regards:ishan_2k

  • jhavineet974jhavineet974 Posts: 2Member
    i think u are bit confused with the name of variables u have taken,in the 2nd printf()[ after if()] u are trying to print m which has been already assigned a value of check.....so whenever the first if statment turns to be true a garbage value gets printed....
  • globalprogglobalprog Posts: 67Member
Sign In or Register to comment.