**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.

is it possible without break and continue

ReplyDelete#include

ReplyDeletevoid 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");

}

}

}

ok priya...its working

Deletethinking great

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

Deletethank u @asha it is easy to understand

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

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

ReplyDeleteits ok......

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

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

ReplyDeleteThanks!

Deletesuppose 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....

ReplyDeletewrite a program to print 3

ReplyDelete323

32123

323

3

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

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

ReplyDeleteThis comment has been removed by the author.

ReplyDeleteThis comment has been removed by the author.

ReplyDelete