patternprogram_204 softethics

Pattern 204

C

#include<stdio.h>

int main()
{
  int i,j;

  for (i=0; i<4; i++)
  {
    for (j=i; j<i+4; j++)
    {
      printf("%d",(j%4)+1);
    }
    printf("\n");
  }
  return 0;
}

C++

#include<iostream.h>

int main()
{
    int i,j;

    for (i=0; i<4; i++)
    {
        for (j=i; j<i+4; j++)
        {
            cout<<(j%4)+1;
        }
        cout<<endl;
    }
    return 0;
}

Java

class PatternProg
{
    public static void main(String args[])
    {
        for (int i = 0; i < 4; i++)
        {
            for (int j = i; j < i + 4; j++)
            {
                System.out.print((j % 4) + 1);
            }
            System.out.println();
        }
    }
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    for (int i = 0; i < 4; i++)
    {
      for (int j = i; j < i + 4; j++)
      {
        Console.Write((j % 4) + 1);
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

for x in range(0, 4):
    for y in range(x, x+4):
      print((y%4)+1, end="")
    print()
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments