Join the social network of Tech Nerds, increase skill rank, get work, manage projects...

• # How to Print Floyd's Triangle in php ?

• 0
• 0
• 0
• 0
• 0
• 0
• 1
• 0
• 936
Comment on it

Hello readers, today I have taken example of Floyds triangle. Floyd's  triangle is a right-angled triangle of  array having natural numbers. The  natural numbers are printed in such a manner , that it will look like right angle triangle. It is named after Mathematician Robert Floyd. Floyd's  triangle is made by filling the rows of the triangle with consecutive natural numbers, starting with 1 in the top left corner.

Here is the program to print Floyd's triangle

``````<html>
<body>

<form method="post" action="index.php">
<label>Enter the number :</label><input type="text" name="number"><br/>
<input type="submit" name="submit">
</form>

<?php
\$a=1;
\$k=htmlspecialchars(\$_POST["number"]);

for(\$i=1; \$i<=\$k; \$i++){

for(\$j=1;\$j<=\$i;\$j++){

echo \$a;
\$a++;
}

print("<br/>");
}
?>

</body>
</html>``````

Output:

1
23
456
78910
1112131415
161718192021
22232425262728
2930313233343536
373839404142434445
46474849505152535455

Comment : In the above example I took an inputbox, in which user entered a number, this number will assign to variable 'k'. Now I have applied for loop which will start from 0, and ends upto variable 'k'(user entered number). Inside for loop, I have used another for loop which will start from 1 and ends at the value of  variable 'i'. Inside this loop I am printing variable 'a' whose starting value is 1 and then incrementing with the for loop.

## 0 Comment(s)

OR
OR
Register

OR
Fill out the form below and instructions to reset your password will be emailed to you:

• Hire
• Post Projects

### Post Projects

• All at 0 Cost ....
• Post Tech Job
• Select Best Bidder
• Track the Project
• Approve Work and Pay safely
• Browse Nerds
• Work
• Find Projects Find Projects
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
View more...
View less...
• Manage
• Company Company

### Manage Company

• All at 0 Cost ....
• Manage Company and Employee Profiles
• Company wide Employee Productivity Reports
• Knowledge Sharing and Collaboration Tools
• Get Sales Lead and Bid for Tech Projects
• Send Invoices and Receive Payment Safely
• Learn
• Nerd Digest Nerd Digest
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
View more...
View less...
• Tech Q & A Tech Q & A
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
View more...
View less...
• Record & Share

### Desktop Recording Tool

• All at 0 Cost ....
• Online tool for Recording Desktop Activity and Audio
• Store and Share from the Cloud
• Creating Software Product Demos
• Creating video tutorials
• Recording and Reporting Software and Project issues as videos