954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with prime numbers please

#include

int main()
{

int pcheck=1,i;
int k=1000



for(i=2;i

Josue198s
Light Poster
28 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

If you're having problems with a do loop, you need to post up code that includes the do loop. ;)

Using CODE TAGS! Putting your code right between code tags, lets your code stay looking like code, and not like a dog's breakfast.

Adak
Nearly a Posting Virtuoso
1,479 posts since Jun 2008
Reputation Points: 425
Solved Threads: 185
 

Your code is not formatted.

Wrong int k=100;

Correct int k = 100

#include<stdio.h>

int main()
{

int pcheck = 1,i;
int k = 1000

for(i = 2;i < k;i++)
{

if((k % i) == 0)
{
pcheck = 0;

break;
}
}

if(pcheck)
{
printf("%d is a prime .\n",k);
}
else
{
printf("%d is not a prime.\n",k);
}

return 0;
}
alexchen
Junior Poster
147 posts since Aug 2010
Reputation Points: -1
Solved Threads: 14
 

Indentation is pretty important too, especially when you have a problem with looping

#include<stdio.h>
 
int main()
{
	int pcheck = 1,i;
	int k = 1000
 
	for(i = 2;i < k;i++)
	{
		if((k % i) == 0)
		{
			pcheck = 0; 
			break;
		}
	}	
 
	if(pcheck)
	{
		printf("%d is a prime .\n",k);
	}
	else
	{
		printf("%d is not a prime.\n",k);
	}

	return 0;
}
chrjs
Junior Poster in Training
96 posts since Feb 2011
Reputation Points: 58
Solved Threads: 19
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: