Pattern 255

Pattern 255 post thumbnail image

C

#include <stdio.h>

int main()
{
  int i,j;

  for (i=5; i>=1; i--)
  {
    for (j=1; j<=i; j++)
    {
      if (i%2!=0)
        printf("%d",j);
      else
        printf("%d",(i+1-j));
    }
    printf("\n");
  }
  return 0;
}

C++

#include<iostream.h>

int main()
{
    int i,j;

    for (i=5; i>=1; i--)
    {
        for (j=1; j<=i; j++)
        {
            if (i%2!=0)
                cout<<j;
            else
                cout<<(i+1-j);
        }
        cout<<endl;
    }
    return 0;
}

Java

class PatternProg
{
    public static void main(String args[])
    {
        for (int i = 5; i >= 1; i--)
        {
            for (int j = 1; j <= i; j++)
            {
                if (i % 2 != 0)
                {
                    System.out.print(j);
                }
                else
                {
                    System.out.print((i + 1 - j));
                }
            }
            System.out.println();
        }

    }
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    for (int i = 5; i >= 1; i--)
    {
      for (int j = 1; j <= i; j++)
      {
        if (i % 2 != 0)
        {
          Console.Write(j);
        }
        else
        {
          Console.Write((i + 1 - j));
        }
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

for x in range(5, 0, -1):
    for y in range(1, x+1):
      if x%2 != 0:
        print(y, end="")
      else:
        print((x+1-y), end="")
    print()
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Patterns