answersLogoWhite

0

The following PHP Code will display the prime numbers between 2 and 50.

You know that 1 is not a Prime number so edit the value for "first for loop" according to your requirements (you can also do it for 2 to 1000 or from 900 to 929)

Output will be:

2is a prime number

3is a prime number

5is a prime number

7is a prime number

11is a prime number

13is a prime number

17is a prime number

19is a prime number

23is a prime number

29is a prime number

31is a prime number

37is a prime number

41is a prime number

43is a prime number

47is a prime number

for($i=2;$i<=50;$i++)

{

$flag=0;// assume prime

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

if(($i%$j)==0)

{

$flag=1;

break;

}

if($flag==0)

echo $i."is a prime number
";//
for jumping to next line after displaying this line..

}

?>

2013-02-22: Replaced $i/2 with sqrt($i) for efficiency by Ryankirgan

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

Write a program to print first 100 alternative prime numbers?

This would require some computer knowledge. It can make it easier to find out the prime numbers without figuring it out in your head.


Program for print prime all number from 1 to 100 in foxpro?

Oh, what a lovely request! In FoxPro, you can create a program to print all prime numbers from 1 to 100 by using a loop to check each number for divisibility only by 1 and itself. If it meets this criteria, you can print it out on the screen. Remember, every number is unique and special, just like a happy little tree in a vast forest.


Write a java script program to print first ten odd natural numbers in C?

Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.


Q2 Write a program to print even numbers between 10 and 50?

You can use int i; for (i = 10; i &lt;= 50; i += 2) {//print i} as a program to print even numbers between 10 and 50.


How do you write a VBnet program to find the prime numbers between 100 to 200?

VBnet program to find the prime numbers between 100 to 200?


Write a C Program to print sum of squares of odd numbers?

#include


How do you write a program in objective c numbers 1-100 prime numbers?

fdsgfhgdfhgdf


How do you write a program to print numbers to 50 except prime?

First, create a for loop from a,1 to 50. Inside of that create another for loop b,2 to a-1. If a/b=int(a/b) then you know it is not prime


Write a C program to find the sum of all prime numbers?

Since there is an infinite set of prime numbers the answer would be infinity.


Write a c program to print prime numbers from 1 to 10000 that has an unit digit which is multiple of 3?

This is a homework question and does not deserve an answer because you will learn nothing other than being lazy.


How do you write a Qbasic program to display these Numbers-0112358132134?

you do this 10 print "0112358132134" use the whole of the thing


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.