Howdy, Stranger!

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

Categories

prime number program

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?i use microsoft compiler.
[code]
/*Program to find all the prime number from zero to a given number and print them*/
#include
#include
main()
{
int num,m,x=0;
int i=2;
int prm=0;
printf("Enter the number
");
scanf("%d",&num);
x=num;
for(x=num;x>=2;x--)
{
while(i<x-1)
{
m=x%i;
if(m==0)
{
break;
}
i++;
}
if(m!=0)
{
prm=x;
printf("%d ",&prm);
}
}
}
[/code]

Comments

Sign In or Register to comment.