How to i implement loops to print the initialised word as foloows:
Thanx in advance.

p
pr
pro
prog
progr
progra
program
programm
programmi
programmin
programming
programmin
programmi
programm
program
progra
progr
prog
pro
pr
p

Hint: Use two for loops separately for the increasing pattern and two for decreasing pattern.

Edited 5 Years Ago by Arbus: n/a

So far i have managed the first loop bt im having problem in implementing a decreasing loop.

#include "stdafx.h";
#include  <iostream.h>
#include  "conio.h"

using namespace std;

int main()
{
	    char wrd[12];
		cout<<"\n Enter a String : ";
		cin.getline(wrd,12);
        int i;
		  int j;
		for ( i = 0; i < wrd[i]; i++ )
		{
			for( j=0; j<=i; j++)

             cout<<wrd[j];
		     cout<<"\n";
		}
//=========================================

//    next loop

//=========================================
		 
        cout<<"C++ Programming"<<"\n\n";
		system("pause");
}

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

In the previous pattern the letters were increasing and now it should decrease for the next pattern. Just decrement values instead of incrementing. The for loops will look like this.

for(i = strlen(wrd)-1;i>=0;i--)
{ for( j=0;j<=i;j++)
  { 
   //complete this
   .
   .
  }
}

Edited 5 Years Ago by Arbus: n/a

In your first for loop the statement i < wrd[i] should be replaced by either: wrd[i] != NULL or i < strlen(wrd) .

You are comparing i to the character code, which works fine when you are limited to twelve characters, since the lowest printable character is 32 (a space). However, if you went beyond that your code would stop working properly.

This question has already been answered. Start a new discussion instead.