patternprogram_416 softethics

Pattern 416 (String Pattern)

C

#include <stdio.h>
#include <string.h>

int main()
{
  char str[] = "SoftEthics";
  int len = strlen(str);
  int i,j;
  int shift=4,x = 0;

  for(i = 0; i < shift; i++)
  {
    for(j = 0; j < shift; j++)
    {
      printf("%c ", str[x++]);
      if (x == len)
        x = 0;
    }
    printf("\n");
  }
  return 0;
}

C++

#include <iostream.h>
#include <string.h>

int main()
{
  char str[] = "SoftEthics";
  int len = strlen(str);
  
  int shift=4,x = 0;

  for(int i = 0; i < shift; i++)
  {
    for(int j = 0; j < shift; j++)
    {
      cout<<str[x++]<<" ";
      if (x == len)
        x = 0;
    }
    cout<<endl;
  }
  return 0;
}

Java

class PatternProg
{
	public static void main(String args[])
	{
	  String str = "SoftEthics";
	  int len = str.length();

	  int shift = 4;
	  int x = 0;

	  for (int i = 0; i < shift; i++)
	  {
		for (int j = 0; j < shift; j++)
		{
		  System.out.print(str.charAt(x++)+" ");
		  
		  if (x == len)
		  {
			x = 0;
		  }
		}
		System.out.println();
	  }
	  
	}
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    string str = "SoftEthics";
    int len = str.Length;

    int shift = 4;
    int x = 0;

    for (int i = 0; i < shift; i++)
    {
      for (int j = 0; j < shift; j++)
      {
        Console.Write(str[x++] + " ");

        if (x == len)
        {
          x = 0;
        }
      }
      Console.WriteLine();
    }


    Console.ReadKey(true);
  }
}

Python

string = "SoftEthics"
length = len(string)
shift = 4
d = 0

for x in range(0, shift):
    for y in range(0, shift):
        print(string[d] + " ", end="")
        d += 1

        if d == length:
           d = 0

    print()
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments