patternprogram_420 softethics

Pattern 420 (String Pattern)

C

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

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


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

C++

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

int main()
{
  char arr[] = "SUMIT";
  int n = strlen(arr);
  int x = 0;
  

  
  for(int i = 0; i < n; i++)
  {
    for(int j = n - 1; j > i; j--)
    {
      cout<<"  "; // 2ws
    }
    for(int k = 1; k <= i + 1; k++)
    {
      cout<<arr[n-k]<<" ";
    }
    cout<<endl;
  }
  return 0;
}

Java

class PatternProg
{
	public static void main(String args[])
	{
	  String arr = "SUMIT";
	  int n = arr.length();
	  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 = 1; k <= i + 1; k++)
		{
		  System.out.print(arr.charAt(n - k)+" ");
		}
		System.out.println();
	  }
	  
	}
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    string arr = "SUMIT";
    int n = arr.Length;
    int x = 0;



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


    Console.ReadKey(true);
  }
}

Python

string = "SUMIT"
n = len(string)
d = 0

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

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