TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Program to Print Pattern 15

Program to Print Pattern 15 on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, linkedlist, tree, graph, pattern, string etc.

<< Back to PROGRAM

Program to print the following pattern (pascal triangle)

Program to print the following pattern (pascal triangle)

Algorithm

  1. Start
  2. Let i be an integer number.
  3. Let j be an integer number.
  4. Let row be an integer number and initialize by 6.
  5. Let coe be an integer number and initialize by 0.
  6. Repeat step 7 to 14 until all value parsed.
  7. Set i = 0 and check I <= row;
  8. Set j = 1 and check j <= row-i;
  9. Print space.
  10. check if j==0 || i==0
  11. set coe = 1;
  12. Else
  13. Set coe = coe * (i+j-1)/j;
  14. Print coe.
  15. End

JAVA

package programs;
public class Pattern11 
{
    public static void main(String[] args) 
    {
        int coe=1,rows = 6;
     for(int i = 0; i < rows; i++) {
            for(int space = 1; space < rows - i; ++space) {
                System.out.print("  ");
            }

            for(int j = 0; j <= i; j++) {
                if (j == 0 || i == 0)
                    coe = 1;
                else
                    coe = coe * (i - j + 1) / j;

                System.out.printf("%4d", coe);
            }
      System.out.println();
        }   
    }
   }

Python

numberOfRows = 7
def formatNumber(number):
  if number<10:
    return "  "+str(number) + " "
  else:
    return " " + str(number) + " "
row = [1]
print("  " * 7 + formatNumber(row[0]))
row.append(1)
print("  " * 6 + formatNumber(row[0]) + formatNumber(row[1]))
row.append(2)
print("  " * 5 + formatNumber(row[0]) + formatNumber(row[1]+row[0]) + formatNumber(row[1]))
row.append(3)
print("  " * 4 + formatNumber(row[0]) + formatNumber(row[3]) +formatNumber(row[3]) + formatNumber(row[1]))
row.append(4)
print("  " * 3 + formatNumber(row[0]) + formatNumber(row[4]) + formatNumber(row[4]+row[2]) +formatNumber(row[4]) + formatNumber(row[1]))
row.append(5)
print("  " * 2 + formatNumber(row[0]) + formatNumber(row[5]) + formatNumber(row[5]+row[5]) + formatNumber(row[5]+row[5]) +formatNumber(row[5]) + formatNumber(row[1]))

C program

#include <stdio.h>
int main()
{
 int co=1,rows = 6;
for(int i = 0; i < rows; i++)
{
    for(int space = 1; space < rows - i; ++space)
    {
        printf("  ");
    }
    for(int j = 0; j <= i; j++) 
    {
        if (j == 0 || i == 0)
            co = 1;
        else
            co = co * (i - j + 1) / j;
        printf("%4d", co);
    }
printf("\n");
}
}

C# program

using System;
public class Program
{
public static void Main()
{
 int row, i, j, k;
 row = 5;
        for (i = 0; i <= row; i++)
        {
        k = 1;
        for (j = i; j <= row - 1; j++)
        Console.Write(" ");
 
        for (j = 0; j <= i; j++)
        {
        Console.Write("{0} ", k);
        k = (k * (i - j) / (j + 1));
        }
        Console.WriteLine();
        }
 Console.ReadLine();  
}
}

PHP Program

<?php
  $co=1;
$rows = 6;
for($i = 0; $i < $rows; $i++)
{
    for($space = 1; $space < $rows - $i; ++$space)
    {
        echo " ";
    }
    for($j = 0; $j <= $i; $j++) 
    {
        if ($j == 0 || $i == 0)
            $co = 1;
        else
            $co = $co * ($i - $j + 1) / $j;
        echo $co." ";
    }
  echo "<br>";
}
?>





Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf