patternprogram_413 softethics

Pattern 413 (String Pattern)

C

#include <stdio.h>
#include <string.h>
int main()
{
  //A char array to hold the string and print a single char at a time.

  char arr[]="SUMIT";

  int len=strlen(arr) ;
  int i,j;

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

  return 0;
}

C++

#include<iostream.h>
int main()
{
//A char array to hold the string and print a single char at a time.

    char arr[]="SUMIT";

    int len=strlen(arr);
    int i,j;

    for (i=len-1; i>=0; i--)
    {
        for (j=0; j<=i; j++)
        {
            cout<<arr[j]<<" ";
        }
        cout<<endl;
    }

    return 0;
}

Java

class PatternProg
{
    public static void main(String args[])
    {
        String str = "SUMIT";

        for (int i = str.length()-1; i >= 0; i--)
        {
            for (int j = 0; j <= i; j++)
            {
                System.out.print(str.charAt(j));
            }
            System.out.println();
        }
    }
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    string str = "SUMIT";

    for (int i = str.Length - 1; i >= 0; i--)
    {
      for (int j = 0; j <= i; j++)
      {
        Console.Write(str[j]);
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

string = "SUMIT"
strlen = len(string)

for x in range(0, strlen):
  print(string[0:strlen-x])
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments