PHP program to print continuous character pattern triangle


To print continuous character pattern triangle in PHP, the code is as follows −

Example

 Live Demo

<?php
function continuous_alphabets($val)
{
   $num = 65;
   for ($m = 0; $m < $val; $m++)
   {
      for ($n = 0; $n <= $m; $n++ )
      {
         $ch = chr($num);
         echo $ch." ";
         $num = $num + 1;
      }
      echo "
";    } } $val = 6; continuous_alphabets($val); ?>

Output

A
B C
D E F
G H I J
K L M N O
P Q R S T U

This is similar to generating a star or a number pattern, the only difference being, continuous characters of English alphabets are generated instead of stars or numbers. The function ‘continuous_alphabets’ is defined that takes the limit as a parameter. The limit value is iterated over and the character is printed and relevant line breaks are also generated in between. The function is called by passing this limit value and the relevant output is generated on the console.

Updated on: 02-Jul-2020

239 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements