I want the following pattern

123454321
1234 4321
123 321
12 21
1 1

I am able to acheive
12345
1234
123
12
1

I am not able to get the logic in the code as the lines increase the spaces should increase...

Please help...this is killing my sleep.

Regards

Vilas

Recommended Answers

All 4 Replies

the pattern is as follows

1234321
123 321
12 21
1 1

Your loop in lines 13-18 are missing a step.

Did you read the Rules? How about the post "Read This Before Posting"?

Your loop in lines 13-18 are missing a step.

Did you read the Rules? How about the post "Read This Before Posting"?

This is my following code...I am missing on the logic here. IF someone can add what i should do to get the pattern

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k;

cout<<"Please enter the number of lines: ";
cin>>k;
                  for(i=1;i<=k;i++)
{
                                              for(j=1;j<k;j++)
                                              cout<<j;
                                             for(l=k-1;l>0;l++)
                                             cout<<l;
                                             cout<<endl;

}

}

The above code is giving me an out put as follows

12345654321
12345654321
12345654321
12345654321
12345654321
12345654321

i am lookin for the output

12345654321
12345 54321
1234     4321
123         321
12             21
1                 1

I have resolved it myself here is the solution for the forum benifit...cheers

#include<iostream.h>
#include<conio.h>
#include<stdio.h>

void main()

{

clrscr();

int i,j,k,val,x=7,blanks=0;

while(i<=7)
{

val=x;

j=1

while(j<=val)

{

cout<<val;
val++;

}


if(i==1)

val--;

k=1;

while(k<=blanks)

{

cout<<" ";

k++;

}

blanks=2*i-1;

while(val>=1)

{

cout<<val;

val--;

}

cout<<endl;

i++;
x--

}


getche();

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.