patternprogram_418 softethics

Pattern 418 (String Pattern)

C

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

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


  for(i = 0; i < shift; i++)
  {
    for(j = 0; j <= i; j++)
    {
      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 shift = 5;
  int x = 0;
  

  
  for(int i = 0; i < shift; i++)
  {
    for(int j = 0; j <= i; j++)
    {
      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 shift = 5;
	  int x = 0;



	  for (int i = 0; i < shift; i++)
	  {
		for (int j = 0; j <= i; j++)
		{
		  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 shift = 5;
    int x = 0;



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

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


    Console.ReadKey(true);
  }
}

Python

string = "SoftEthics"
shift = 5
d = 0


for x in range(0, shift):
    for y 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