Fibonacci Series10 Mar 2025 | 2 min read Fibonacci series is the one in which you will get your next term by adding previous two numbers. For example, and so on. Logic:
Example: We'll show an example to print the first 12 numbers of a Fibonacci series. ExampleExecute NowOutput: ![]() Fibonacci series using Recursive functionRecursion is a phenomenon in which the recursion function calls itself until the base condition is reached. ExampleExecute NowOutput: ![]() Next TopicReverse number |
Sum of Digits To find sum of digits of a number just add all the digits. For example, 14597 = 1 + 4 + 5 + 9 + 7 14597 = 26 Logic: Take the number. Divide the number by 10. Add the remainder to a variable. Repeat the process until remainder is 0. Example: Given...
1 min read
Area of a Rectangle Area of a rectangle is calculated by the mathematical formula, Length ∗ Breadth = Area Logic: Take two variables. Multiply both of them. Area of Rectangle in PHP Program to calculate area of rectangle with length as 14 and width as 12 is shown. Example: Example <?php $length = 14; $width...
1 min read
Tutorial Compiler Programs OOPs Functions Interview Questions | PHP Programming Examples PHP programs are frequently asked in the interview. These programs can be asked from basics, control statements, array, string, oops,...
2 min read
Reverse number A number can be written in reverse order. For example 12345 = 54321 Logic: Declare a variable to store reverse number and initialize it with 0. Multiply the reverse number by 10, add the remainder which comes after dividing the number by 10. Reversing Number in PHP Example: Below progrem shows digits...
1 min read
Star Triangle The star triangle in PHP is made using for and foreach loop. There are a lot of star patterns. We'll show some of them here. Pattern 1 Example <?php for($i=0;$i<=5;$i++){ for($j=5-$i;$j>=1;$j--){ echo "* "; } echo "<br>"; } ?> Execute Now Output: Pattern 2 Example <?php for($i=0;$i<=5;$i++){ for($j=1;$j<=$i;$j++){ echo "* "; } echo "<br>"; } ?> Execute Now Output: Pattern 3 Example <?php for($i=0;$i<=5;$i++){ for($k=5;$k>=$i;$k--){ echo " "; } for($j=1;$j<=$i;$j++){ echo "* "; } echo "<br>"; } for($i=4;$i>=1;$i--){ for($k=5;$k>=$i;$k--){ echo " "; } for($j=1;$j<=$i;$j++){ echo "* "; } echo "<br>"; } ?> Execute...
1 min read
Subtracting Two Numbers There are three methods to subtract two numbers: Subtraction in simple code in PHP Subtraction in form in PHP Subtraction without using arithmetic operator (+). Subtraction in Simple Code Subtraction of two numbers 30 and 15 is shown. Example: Example <?php $x=30; $y=15; $z=$x-$y; echo "Difference: ",$z; ?> Execute Now Output: Subtraction in Form By inserting values in the form...
1 min read
Alphabet Triangle Method There are three methods to print the alphabets in a triangle or in a pyramid form. range() with for loop chr() with for loop range() with foreach loop Logic: Two for loops are used. First for loop set conditions to print 1 to 5 rows. Second for loop set conditions...
1 min read
Swapping two numbers Two numbers can be swapped or interchanged. It means first number will become second and second number will become first. For example a = 20, b = 30 After swapping, a = 30, b = 20 There are two methods for swapping: By using third variable. Without using third variable. Swapping...
1 min read
Number Triangle Number triangle in PHP can be printed using for and foreach loop. There are a lot of patterns in number triangle. Some of them are show here. Pattern1 Example <?php $k=1; for($i=0;$i<4;$i++){ for($j=0;$j<=$i;$j++){ echo $k." "; $k++; } echo "<br>"; } ?> Execute Now Output: Pattern 2 Example <?php $k=1; for($i=0;$i<5;$i++){ for($j=0;$j<=$i;$j++){ if($j%2==0) { $k=0; } else { $k=1; } echo $k." "; } echo "<br>"; } ?> Execute Now Output: Pattern 3 Example <?php for($i=0;$i<=5;$i++){ for($j=1;$j<=$i;$j++){ echo $j; } echo "<br>"; } ?> Execute Now Output: Pattern 4 Example <?php for($i=0;$i>=5;$i++){ for($j=1;$j>=$i;$j++){ echo $i; } echo "<br>"; } ?< Execute...
1 min read
Adding Two Numbers There are three methods to add two numbers: Adding in simple code in PHP Adding in form in PHP Adding without using arithmetic operator (+). Adding in Simple Code Addition of two numbers 15 and 30 is shown here. Example: Example <?php $x=15; $y=30; $z=$x+$y; echo "Sum: ",$z; ?> Execute Now Output: Adding in Form Two numbers can be added...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India