Pattern Printing - String Characters
Please do comment If u have any Queries!
Given a string S of length L, the program must print the pattern as described in the Example Input/Output.
Input Format:
First line contains the string S.
First line contains the string S.
Output Format:
L lines containing the desired pattern.
L lines containing the desired pattern.
Boundary Condition:
2 <= L <= 100
2 <= L <= 100
Example Input/Output 1:
Input:
ABCD
Input:
ABCD
Ouput:
A
BB
CCC
DDDD
A
BB
CCC
DDDD
Example Input/Output 2:
Input:
EAGLE
Input:
EAGLE
Ouput:
E
AA
GGG
LLLL
EEEEE
E
AA
GGG
LLLL
EEEEE
Code:
#include <iostream>
#include<string.h>
using namespace std;
int main(int argc, char** argv)
{
char str[100];
int i,j,k=0;
cin>>str;
for(i=1;i<=strlen(str);i++)
{
for(j=0;j<i;j++)
{
cout<<str[k];
}
k++;
cout<<"\n";
}}
Please do comment If u have any Queries!
import java.util.*;
ReplyDeletepublic class Hello {
public static void main(String[] args) {
//Your Code Here
Scanner sc = new Scanner(System.in);
String s = sc.next();
char [] c = s.toCharArray();
int t =0;
for(int i =1;i<=c.length;i++)
{
for(int j=0;j<i;j++)
{
System.out.print(c[t]);
}
t++;
System.out.println();
}
}
Diminish an opportunity to-advertise, since there is no hold up time as for outline endorsement and amendments. VSL
ReplyDelete