Pattern 417 (String Pattern)

Pattern 417 (String Pattern) post thumbnail image

C

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

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

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

C++

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

int main()
{
  char str[] = "SoftEthics";
  int x = strlen(str)-1;
  
  int shift=4;

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

Java

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

	  int shift = 4;

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

C#

using System;

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

    int shift = 4;

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

        if (x == -1)
        {
          x = str.Length - 1;
        }
      }
      Console.WriteLine();
    }


    Console.ReadKey(true);
  }
}

Python

string = "SoftEthics"
d = len(string) - 1
shift = 4

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

    if d == -1:
        d = len(string) - 1
    print()
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Patterns