DIGIT-ARC read-only archive · snapshot: July 23, 2026

How to print this ???

16 posts · originally from https://geek.digit.in/community/threads/how-to-print-this.82706/

~Phenom~
~Phenom~ Original post #1
Mar 14, 2008 at 10:45 PM
Hi,
I need a program which can print a pyramid like below , with taking height of pyramid in integer from user as input.

********** A
*********A B A
********A B B A
*******A B C B A
*******A B C C B A

Asterisks should be replaced by whitespaces.Please reply ....
Zangetsu
Mar 15, 2008 at 10:50 AM
This pyramid structure we created in C & C++ :)

Do u want the same in those languages?
~Phenom~
Mar 15, 2008 at 12:34 PM
This pyramid structure we created in C & C++ :)

Do u want the same in those languages?
Any language will do yaar, I just want the logic. U may give it to me in C/C++/Java...
Pathik
Pathik #4
Mar 15, 2008 at 1:03 PM
Ignoring the spaces, Shouldn't it be
A
AA
ABA
ABBA
ABCBA
....
~Phenom~
Mar 15, 2008 at 1:29 PM
^^I put those asterisks , because with spaces , it was getting LHS like the one u gave. The top most A should be in the middle of the line.
M
Mar 15, 2008 at 2:05 PM
Take n as input from user;

for x=n to 1
for y=1 to x
print " "
next y
for z=n to x
print "* "
next z
next x

Output:
*
* *
* * *
* * * *
* * * * *

Hope this helps!:)
M
Mar 15, 2008 at 3:34 PM
^^ that won't do if the query is right. See there's 1 in the first line, then 3, 4, 5 and 6. Looks really odd to me.
1,3,5,7 could still have been understood but 1,3,4,5,6 doesn't make any sequence to me :?
F
FilledVoid #8
Mar 15, 2008 at 4:08 PM
Yeah what mehulved said.

********** A
*********A B A
********A B B A
*******A B C B A
*******A B C C B A

Your pyramid is either wrong or doesnt follow a predetermined sequence.

Should it be ?

Code:
   A
  ABA
 ABCBA
ABCDCBA
Pathik
Pathik #9
Mar 15, 2008 at 4:38 PM
^^ that won't do if the query is right. See there's 1 in the first line, then 3, 4, 5 and 6. Looks really odd to me.
1,3,5,7 could still have been understood but 1,3,4,5,6 doesn't make any sequence to me :?

Yeah what mehulved said.

********** A
*********A B A
********A B B A
*******A B C B A
*******A B C C B A

Your pyramid is either wrong or doesnt follow a predetermined sequence.

Should it be ?

Code:
   A
  ABA
 ABCBA
ABCDCBA
Yup. That's what I said na!
Either it has to be 1-2-3-4-5 or 1-3-5-7-9
There is something wrong.
Garbage
Garbage #10
Mar 15, 2008 at 5:37 PM
Is it like Pascal Triangle ??
~Phenom~
~Phenom~ #11
Mar 15, 2008 at 5:56 PM
Should it be ?

Code:
   A
  ABA
 ABCBA
ABCDCBA

Yes, this is what I want , sorry for giving flawed one earlier. Can I please have the code now ????
ring_wraith
Mar 15, 2008 at 6:05 PM
Here you go, it's in C++

The following will print this:
***A
**ABA
*ABCBA
ABCDCBA

prerequisite:array 'a' with A-Z in alphabetical order and 'n' is upto which character it is required. Like n=3 for C. in the above case, n=4

for (i=1,s=n-1; i<n,s>=0;s--,i++)
{
for(j=1;j<=s;j++)
{cout<<" ";}

for(j=0;j<i;j++)
{cout<<a[j];}

for(j=j;//not sure about this part, try it j>=0;j++)
{cout<<a[j];}

cout<<endl;
}
~Phenom~
~Phenom~ #13
Mar 15, 2008 at 7:54 PM
^^Do not seem to work. Others please help, now that u know the right pyramid , please pour in ur code ....
Pathik
Pathik #14
Mar 15, 2008 at 8:42 PM
Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int SIZE,i,j,k,l;
char X='A';
printf("Enter the number of rows\n");
scanf("%d",&SIZE);
//a=5;

for(i=0;i<SIZE;i++)
{
	for(j=0;j<SIZE-i-1;j++)
	{
	printf(" ");
	}
	for(k=0;k<i+1;k++)
	{
	printf("%c",X);
	X++;
	}
	X--;
	for(l=0;l<i;l++)
	{
	X--;
	printf("%c",X);
	}
	X='A';
	printf("\n");
}



getch();
return 0;
}


//****A
//***ABA
//**ABCBA
//*ABCDCBA
//ABCDEDCBA
~Phenom~
~Phenom~ #15
Mar 15, 2008 at 9:00 PM
^^Thanx Buddy. :)
redhat
redhat #16
Mar 19, 2008 at 5:49 PM
Code:
public void pascal_char(char a)
        {
            int sp=((int)a-1)-96; //ASCII for character a is 96
            //I Loop conrols the vertical movement
            for(char i='a'; i<=a; i++)
            {
                //K loop prints the spaces
                for(int k=0; k<sp; k++)
                {
                    System.out.print(" ");
                }
                sp--; //Decrease spaces by one in each line
                //J Loop prints the characters, Forwards in each line
                for(char j='a'; j<=i; j++)
                {
                    System.out.print(j);
                }
                //L Loop prints the chars, Backwards in each line
                for(char l= (char)(i-1); l>='a'; l--)
                {
                    System.out.print(l);
                }
                System.out.println();
            }
        }

In Java.....