Strings in C++

Hi frnds
I am having some kind of problem in strings.. I have to write a String program whose output is like this

Let the string is :-

Enter string : "Computer Programming"
C
Co
Com
Comp
Compu
Comput
Compute
Computer
Computer P
Computer Pr
Computer Pro
Computer Prog
Computer Progr
Computer Progra
Computer Program
Computer Programm
Computer Programmi
Computer Programmin
Computer Programming

I Have tried much to make this program but not successful..Can anyone help me. Thank you
Last edited on
If you want to print a triangle out of user input like that, you'll have to print strings char by char. This is just two nested for loops. One, i = 1 to strlen(input), and another, j = 0 to i.
Thank u for ur suggestion.. But plz can u write that whole nested loops condition of this program if possible ? ..
1
2
3
4
5
6
string word = "ComputerProgramming";
for (int i=0; i < word.length(); i++)
{
  for (int j=0; j<=i; j++) cout << word[j];
  cout << endl;
}


Two for loops, one for each line, and one for each character.
Thanks a lot friend..... I know it was quite simple but i was not getting through the logic... Thank You once again you solved my problem
Topic archived. No new replies allowed.