04/03/2017

Geeksforgeeks Solution For " Triangle shrinking downwards "

GeeksforGeeks Solution For School Domain .Below You Can Find The Solution Of Basic ,Easy ,Medium ,Hard .You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Given a string of a constant length, print a triangle out of it. The triangle should start with the given string and keeps shrinking downwards by removing one character from the begining of the string.
The spaces on the left side of the triangle should be replaced with dot character.

Submit Your Solution :- Click Here 


Solution :- 

Method 1 :-

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main() 
{   
    int t;
cin>>t;
int i,j,k=0,temp=0;
string str;
while(t--)
{   
   k=0;
   cin>>str;
   temp=str.length();
   int i=0;
   do
   {
       cout<<str<<endl;
       str[i]='.';
       i++;
   }while(i<temp);
}
return 0;

}

Method 2 :-

#include <iostream>
#include<cstring>
using namespace std;
int main() 
{   
    int t;
cin>>t;
while(t--)
{   
   int i,j,k=0,temp=0;
   string str;
   cin>>str;
   temp=str.length();
   for(i=0;i<temp;i++)
   {
       for(k=0;k<i;k++)
           cout<<".";
       for(j=i;j<temp;j++)
           cout<<str[j];
        cout<<endl;
   }
}
return 0;
}



Output:-

Method 1 :-


Geeksforgeeks Solution For " Triangle shrinking downwards "


Method 2 :-


Geeksforgeeks Solution For " Triangle shrinking downwards "

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

1 comment: