Pattern 419 (String Pattern)

Pattern 419 (String Pattern) post thumbnail image

C

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

int main()
{
  char arr[] = "SoftEthics";
  int n = 5;
  int x = 0;
  int i,j,k;


  for(i = 0; i < n; i++)
  {
    for(j = n - 1; j >= i; j--)
    {
      printf(" ");
    }
    for(k = 0; k <= i; k++)
    {
      printf("%c",arr[x++]);

      if (x == strlen(arr))
        x = 0;
    }
    printf("\n");
  }
  return 0;
}

C++

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

int main()
{
  char arr[] = "SoftEthics";
  int n = 5;
  int x = 0;
  

  
  for(int i = 0; i < n; i++)
  {
    for(int j = n - 1; j > i; j--)
    {
      cout<<"  ";
    }
    for(int k = 0; k <= i; k++)
    {
      cout<<arr[x++]<<" ";

      if (x == strlen(arr))
        x = 0;
    }
    cout<<endl;
  }
  return 0;
}

Java

class PatternProg
{
	public static void main(String args[])
	{
	  String arr = "SoftEthics";
	  int n = 5;
	  int x = 0;



	  for (int i = 0; i < n; i++)
	  {
		for (int j = n - 1; j > i; j--)
		{
		  System.out.print("  "); //2ws
		}
		for (int k = 0; k <= i; k++)
		{
		  System.out.print(arr.charAt(x++)+" ");
		  
		  if (x == arr.length())
		  {
			x = 0;
		  }
		}
		System.out.println();
	  }
	  
	}
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    string arr = "SoftEthics";
    int n = 5;
    int x = 0;



    for (int i = 0; i < n; i++)
    {
      for (int j = n - 1; j > i; j--)
      {
        Console.Write("  "); //2ws
      }
      for (int k = 0; k <= i; k++)
      {
        Console.Write(arr[x++] + " ");

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


    Console.ReadKey(true);
  }
}

Python

string = "SoftEthics"
n = 5
d = 0

for x in range(0, n):
  for y in range(n - 1, x, -1):
      print("  ", end="")  # 2ws
  for z in range(0, x + 1):
	  print(string[d] + " ", end="")
	  d += 1

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

Related Patterns