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 = n-1; j > i; j--)
{
printf(" ");
}
for(k = 0; k <= 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 = len-1; j > i; j--)
{
cout<<" "; // 2ws
}
for(int k = 0; k <= 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 = len - 1; j > i; j--)
{
System.out.print(" "); //2ws
}
for (int k = 0; k <= 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 = len - 1; j > i; j--)
{
Console.Write(" "); //2ws
}
for (int k = 0; k <= 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(length - 1, x, -1):
print(" ", end="") # 2ws
for z in range(0, x + 1):
print(string[z]+" ",end="")
print()