Saturday, 4 March 2017

Geeksforgeeks Solution For " Triangle growing 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 first character of the string and keeps growing downwards by adding one character from the string.
The spaces on the left side of the triangle should be replaced with dot character.

Submit Your Solution :- Click Here 


Solution :-

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


Output:-


Geeksforgeeks Solution For " Triangle growing downwards "

No comments:
Write comments

Recommended Posts × +