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:
is it possible without break and continue
#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");
}
}
}
is it possible to use some other function instead of main??
its ok......
send program to print series 1+(1+2)+(1+2+3)+(1+2+3+n)in c language
initialise i=2 instead of i=1, otherwise 1 also print in prime no series.
Thanks!
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....
ok priya...its working
thinking great
write a program to print 3
323
32123
323
3
please guide me to understand the ''fact'' command..... I could not understand it...
thank u @asha it is easy to understand
is it possible using wilthout while codition....use if condition
is it possible using wilthout while codition....use if condition
you have used fact term.but why?plz make it clear to us.
Anyone help me to understand creating pascal triangle. Please... I can't understand.
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
WRITE A PROGRAM IN JAVA TO PRINT THE PRIME NUMBERS UPTO 300 IN A FIBONACCI SERIES.
#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;
}
please tell me program to find all possibilities sum of any prime numbers from 1 to 32 to give the output 32
a
Post a Comment