top of page
Writer's pictureThe Tech Platform

Write a PHP program to print the Alphabet Triangle Pattern.

Some different alphabet triangle patterns using range() function in PHP are shown below.


Pattern 1

<?php  
$alpha = range('A', 'Z');  
for($i=0; $i<5; $i++){   
 for($j=5; $j>$i; $j--){  
 echo $alpha[$i];  
    }  
 echo "<br>";  
}  
?>  

Output:

















Pattern 2

<?php  
$alpha = range('A', 'Z');  
for($i=0; $i<5; $i++){   
 for($j=0; $j<=$i; $j++){  
 echo $alpha[$i];  
    }  
 echo "<br>";  
}  
?>  

Output:













Pattern 3

<?php  
$alpha = range('A', 'Z');  
for($i=0; $i<5; $i++){   
 for($j=0; $j<=$i; $j++){  
 echo $alpha[$j];  
    }  
 echo "<br>";  
}  
?>  

Output:


















Pattern 4

<?php  
$alpha = range('A', 'Z');  
for($i=0; $i<5; $i++){   
 for($j=4; $j>=$i; $j--){  
 echo $alpha[$j];  
    }  
 echo "<br>";  
}  
?>  

Output:
















Pattern 5

<?php  
$alpha = range('A', 'Z');  
for ($i=5; $i>=1; $i--) {    
 for($j=0; $j<=$i; $j++) {    
 echo ' ';    
  }  
 $j--;  
for ($k=0; $k<=(5-$j); $k++) {    
 echo $alpha[$k];   
}    
echo "<br>\n";  
}  
?>  


Output:


















Source: Javapoint


The Tech Platform

0 comments

Recent Posts

See All

Comments


bottom of page