PHP Programs

Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 12: Write a PHP program that finds out the sum of first n odd numbers.


<!DOCTYPE html>
	<title>PHP Programs</title>
	<form method="GET" action="">
		Enter Number: <input type="Text" name="num1"><br/>
		<input type="Submit" name="submit" value="Odd_sum">

		if(isset($_GET["submit"]) == "Odd_sum")
			$sum =0;
			$var1 =$_GET["num1"];
			echo"<br/>First ".$var1."odd number is : ";
			for ($i=1; $i <=2*$var1 ; $i++)
					echo $i."";
					$sum =$sum+$i;
			echo"<br/>Sum of first ".$var1."odd number is : ";
			echo $sum;

If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.