Breaking

Saturday 9 September 2017

Pattern Printing - String Characters

                   Pattern Printing - String Characters

   

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.
Output Format:
L lines containing the desired pattern.
Boundary Condition:
2 <= L <= 100
Example Input/Output 1:
Input:
ABCD
Ouput:
A
BB
CCC
DDDD
Example Input/Output 2:
Input:
EAGLE
Ouput:
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!

2 comments:

  1. import java.util.*;
    public 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();
    }

    }

    ReplyDelete
  2. Diminish an opportunity to-advertise, since there is no hold up time as for outline endorsement and amendments. VSL

    ReplyDelete

Like