⭐ Right Half Pyramid Pattern
Aapko N rows ka ek Right Half Star Pyramid banana hai.
- Row 1 →
* - Row 2 →
** - Row 3 →
*** - …
- Row N →
*****...(N stars)
Is pattern mein stars left side se align hote hain.
<?php
// Yaha par hum N ki value set kar rahe hain
$N = 5;
// Outer loop rows ko control karta hai
for ($i = 1; $i <= $N; $i++) {
// Inner loop har row me stars print karega
for ($j = 1; $j <= $i; $j++) {
echo "*";
}
// Har row ke baad next line
echo "\n";
}
?>
PHPExplanation (Line-by-Line):
✅ $N = 5;
Yeh bata raha hai ki hume 5 rows ka pattern banana hai.
✅ for ($i = 1; $i <= $N; $i++)
- Yeh outer loop hai.
irepresent karta hai row number.- Jab
i = 1hoga → row 1 - Jab
i = 2hoga → row 2
Aur aise hi N tak chalega.
✅ for ($j = 1; $j <= $i; $j++)
- Yeh inner loop hai jo stars print karega.
- Har row me jitna
ihoga utne hi stars print honge.
Example:
- Row 1 →
i = 1→ 1 star - Row 2 →
i = 2→ 2 stars
✅ echo "\n";
Her row complete hone ke baad next line me chala jaata hai.
User Input + HTML
<!DOCTYPE html>
<html>
<head>
<title>Right Half Star Pyramid in PHP</title>
</head>
<body>
<!-- User input form -->
<form method="post">
<label>Enter number of rows (N):</label>
<input type="number" name="rows" required>
<button type="submit">Generate Pyramid</button>
</form>
<pre>
<?php
// Check agar form submit hua hai
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// User se N ki value lena
$n = $_POST['rows'];
// Right Half Pyramid banana
for ($i = 1; $i <= $n; $i++) {
// Har row me stars print karne ka loop
for ($j = 1; $j <= $i; $j++) {
echo "*";
}
// Next line
echo "\n";
}
}
?>
</pre>
</body>
</html>
PHP1️⃣ User Input Form
- User
Nenter karega (rows ki sankhya). - Form
POSTmethod se data PHP ko bhej raha hai.
2️⃣ PHP Code
- Hum check karte hain ki form submit hua ya nahi:
if ($_SERVER["REQUEST_METHOD"] == "POST")PHP3️⃣ Stars Print Karna
- Outer loop rows banata hai:
for ($i = 1; $i <= $n; $i++)PHP- Inner loop stars print karta hai:
for ($j = 1; $j <= $i; $j++)PHP4️⃣ Output Example (N = 5)
*
* *
* * *
* * * *
* * * * *Markdownright half pyramid pattern,right half star pattern,star pattern in php,php pattern programs,php star pyramid,php right triangle pattern,loop programs in php,php nested loop examples,star pattern coding,simple pattern program,right triangle star program,php pattern questions,php interview pattern questions,pattern program for beginners,php print star,php for loop pattern,php star printing,php star triangle,right aligned triangle pattern,coding pattern tutorials,pattern logic explanation,php programming basics,php for students,star pattern diagram,php pattern with rows and columns,php coding exercise

Welcome to HindiTutorials, your go-to platform for learning and mastering concepts in Hindi! Our mission is to make education accessible and simple for everyone by providing high-quality tutorials on programming, technology, and various other topics.