(Hint: Use nested loops, break and continue statements.)

Improvements:

The work done by the computer is considerably used..if we chuck out all the even numbers..cuz even numbers cannot be prime numbers (except the number 2)

Also, 1 is not a prime number. Instead..it is a Unique Number.

#include<stdio.h>

#include<stdio.h>

main()

**{**

**int**number, div, ifprime;

**for**(number=2;number<=300;number++)

**{**

**for**(div=2; div<number; div++)

**{**

**if**(number%div==0)

**{**

ifprime=0;

**break**;

**}**

ifprime=1;

**}**

**if**(ifprime)

**{**

printf("\n%d", number);

**}**

**}**

**}**

The File can be found at:

Download File

## 20 comments:

very cofusing code

what is ifprime?

in if(ifprime), what is ifprime value?

what is ifprime value in if(ifprime)?

That's just a variable!

Used to give 0 or 1 value based on whether that no is prime or not!

If it is 1, it is a prime!

its very confusing..... pls elaborate wid a simple method....

Take a simple mehthod

#include

void main()

{

int a,b;count=2;

for(a=3;a<=50;a++)

{

for(b=2;b<=a-1;b++)

if(a%b==0)

break;

else if(b==a-1)

{

count=count+1;

printf("%d is a prime number\n",a);

}

}

getche();

}

@abdul

why did ya introduce count in here ????

whats the use ??

#include

int main()

{

int num,div;

for(num=2;num<=300;num++)

{

for(div=2;div<num;div++)

{

if((num%div==0))

{

break;

}

else if(div==num-1)

{

printf ("\n%d",num);

}

}

}

return(0);

}

tuhadi ma da phuda panchodo ya bnaya h q

even more simple is here...

#include

void main()

{

int i,num;

for(num=2;num<=1000 ;num++)

{

for(i=2;i<=num;i++)

{ if(num%i==0)

break;

}

if(i==num)

printf("\n%d is Prime",num);

}

}

realy good solution...!!!

realy good solution

Fucking solution.

int i,j;

for (i = 3; i <= 300; i++)

{

for (j = 2; j < i; j++)

{

if(i % j == 0)

//printf("%d\t",i);

break;

}

if (i == j)

printf("%d\t", i);

}

Sorry.. Here is the final one. There was a mistake in my earlier one :)

int i,j;

printf("2\t");

for (i = 3; i <= 300; i++)

{

for (j = 2; j < i; j++)

{

if(i % j == 0)

break;

}

if (i == j)

printf("%d\t", i);

}

This may help!

#include

#include

main()

{

clrscr();

int i,n;

printf("The prime numbers b/w 1 and 300 are\n");

for(n=1;n<=300;n++)

{

i=2;

for(i=2;i<=n-1;i++)

{

if(n%i==0)

{break;

}

}

if(i==n)

printf("%d\n",n);

}

getch();

}

This may help!

#include

#include

main()

{

clrscr();

int i,n;

printf("The prime numbers b/w 1 and 300 are\n");

for(n=1;n<=300;n++)

{

i=2;

for(i=2;i<=n-1;i++)

{

if(n%i==0)

break;

}

if(i==n)

printf("%d\n",n);

}

getch();

}

Post a Comment