patternprogram_422 softethics

Pattern 422 (String Pattern)

C

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

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

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

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

C++

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

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

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

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

Java

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


	  for (int i = 1; i <= n; i++)
	  {
		for (int j = n; j > i; j--)
		{
		  System.out.print(" ");
		}
		for (int k = 1; k < 2 * i; k++)
		{
		  System.out.print(str.charAt(x++));

		  if (x == str.length())
		  {
			x = 0;
		  }
		}
		System.out.println();
	  }
	  
	}
}

C#

using System;

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


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

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

    Console.ReadKey(true);
  }
}

Python

string = "SoftEthics"
n = 5
d = 0

for x in range(1, n + 1):
    for y in range(n, x, -1):
        print(" ", end="")
    for z in range(1, 2 * x):
        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
Inline Feedbacks
View all comments