Print prime numbers between 1-300 using break and continue in c


Print prime numbers between 1-300 using break and continue in c


#include <math.h>
#include <stdio.h>
main(){
  int i, j;
  i = 2;
  while ( i < 300 ){
     j = 2;
     while ( j < sqrt(i) ){
         if ( i % j == 0 )
            break;
         else{
            ++j;
            continue;
         }
      }
      if ( j > sqrt(i) )
            printf("%d\t", i);
      ++i;
  }
  return 0;
}


Definition of prime number:


A natural number greater than one has not any other divisors except 1 and itself. In other word we can say which has only two divisors 1 and number itself. For example: 5
Their divisors are 1 and 5.

Note: 2 is only even prime number.

Example of prime numbers : 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199 etc.




10. Write a c program to add two numbers without using addition operator.
11. Write a c program to subtract two numbers without using subtraction operator.
15. Write a c program to solve quadratic equation.
18. Write a c program which passes structure to function.
28. Write a c program which takes password from user.
29. Write a scanf function in c which accept sentence from user.
30. Write a scanf function in c which accept paragraph from user.

24 comments:

bishajit said...

is it possible without break and continue

Unknown said...

#include
void main(){
int i,j,fact;
for(i=1;i<=300;i++)
{
fact=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
fact++;
}
if(fact==2)
{
printf("%d",i);
printf("\n");
}
}

}

Deepika said...

is it possible to use some other function instead of main??

Bagesh Kumar Singh said...

its ok......

neha vyas said...

send program to print series 1+(1+2)+(1+2+3)+(1+2+3+n)in c language

Anonymous said...

initialise i=2 instead of i=1, otherwise 1 also print in prime no series.

Priyanka kumari said...

Thanks!

Anonymous said...

suppose any number is given eg:a=12345 then addition of first number and last number eg:1+5=6 like this ,so early as possible....

Anonymous said...

ok priya...its working
thinking great

Unknown said...

write a program to print 3
323
32123
323
3

Anonymous said...

please guide me to understand the ''fact'' command..... I could not understand it...

Unknown said...

thank u @asha it is easy to understand

Unknown said...

is it possible using wilthout while codition....use if condition

Unknown said...

is it possible using wilthout while codition....use if condition

Unknown said...
This comment has been removed by the author.
Unknown said...
This comment has been removed by the author.
Unknown said...

you have used fact term.but why?plz make it clear to us.

Unknown said...

Anyone help me to understand creating pascal triangle. Please... I can't understand.

Unknown said...

I want a C program to print prime numbers. but here condition is to print only the value between 5 to 10, 15 to 20, 25 to 30....... so on

Anonymous said...

WRITE A PROGRAM IN JAVA TO PRINT THE PRIME NUMBERS UPTO 300 IN A FIBONACCI SERIES.

numguitar66 said...

#include
int main(){
int i,j;
for(i=1;i<=300;i++){
for(j=2;j<=i;j++){
if(i%j==0){
break;
}
}
if(i==j){
printf("%d ",i);
}
}
return 0;
}

Unknown said...

please tell me program to find all possibilities sum of any prime numbers from 1 to 32 to give the output 32

Sajib said...
This comment has been removed by the author.
Steven said...

a