patternprogram_415 softethics

Pattern 415 (String Pattern)

C

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

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


  for(i = 0; i < n; i++)
  {
    for(j = i; j > 0; j--)
    {
      printf("  ");
    }

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

C++

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

int main()
{
  char arr[] = "SUMIT";
  int len = strlen(arr);
  
  for(int i = 0; i < len; i++)
  {
    for(int j = i; j > 0; j--)
    {
      cout<<"  "; // 2ws
    }

    for(int k = 0; k < len - i; k++)
    {
      cout<<arr[k]<<" ";
    }
    cout<<endl;
  }
  return 0;
}

Java

class PatternProg
{
	public static void main(String args[])
	{
	  String arr = "SUMIT";
	  int len = arr.length();

	  for (int i = 0; i < len; i++)
	  {
		for (int j = i; j > 0; j--)
		{
		  System.out.print("  "); //2ws
		}

		for (int k = 0; k < len - i; k++)
		{
		  System.out.print(arr.charAt(k)+" ");
		}
		System.out.println();
	  }
	  
	}
}

C#

using System;

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

    for (int i = 0; i < len; i++)
    {
      for (int j = i; j > 0; j--)
      {
        Console.Write("  "); //2ws
      }

      for (int k = 0; k < len - i; k++)
      {
        Console.Write(arr[k] + " ");
      }
      Console.WriteLine();
    }


    Console.ReadKey(true);
  }
}

Python

string = "SUMIT"
length = len(string)

for x in range(0, length):
  for y in range(x, 0, -1):
     print("  ", end="")  # 2ws
  for z in range(0, length - x):
     print(string[z] + " ", end="")
  print()
5 1 vote
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments