Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5428
Number of posts: 16949

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
prime number program Posted by yak98 on 16 Jun 2012 at 8:37 AM
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.
/*Program to find all the prime number from zero to a given number and print them*/
#include<stdio.h>
#include<stdlib.h>
main()
{
int num,m,x=0;
int i=2;
int prm=0;
printf("Enter the number\n");
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);
	}
}
}





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.