Pattern 171

Pattern 171 post thumbnail image

C

#include<stdio.h>

#include<math.h>
int main()
{
  int size=3;  //limit
  int i,j;

  for(i=size; i>=-size; i--)
  {
    for(j=size; j>=abs(i); j--)
    {
      printf("%d",j);
    }
    printf("\n");
  }
  return 0;
}

C++

 #include<iostream.h>
 
 #include<math.h>
 int main()
 {
 int size=3;  //limit
 int i,j;
 
 for(i=size;i>=-size;i--){
 for(j=size;j>=abs(i);j--)
 {
 cout<<j;
 }
 cout<<endl;
 }
 return 0;
 }

Java

  class PatternProg
  {
     public static void main(String args[])
     {
     int size = 3; //limit
     int i;
     int j;
      
     for (i = size;i >= -size;i--)
     {
     for (j = size;j >= Math.abs(i);j--)
     {
     System.out.print(j);
     }
     System.out.print("\n");
     }
      
     }
 }

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int size = 3; //limit

    for (int i = size; i >= -size; i--)
    {
      for (int j = size; j >= Math.Abs(i); j--)
      {
        Console.Write(j);
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

size = 3
for x in range(size, -(size + 1), -1):
    for y in range(size, abs(x) - 1, -1):
        print(y, end="")
    print()

Tutorial (YouTube)

0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Patterns