PDA

View Full Version : How to print this ???


~Phenom~
14-03-2008, 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 ....

KaranTh85
15-03-2008, 10:50 AM
This pyramid structure we created in C & C++ :)

Do u want the same in those languages?

~Phenom~
15-03-2008, 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
15-03-2008, 01:03 PM
Ignoring the spaces, Shouldn't it be
A
AA
ABA
ABBA
ABCBA
....

~Phenom~
15-03-2008, 01: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.

mukeshsayshi
15-03-2008, 02: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!:)

mehulved
15-03-2008, 03: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 :?

FilledVoid
15-03-2008, 04: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 ?


A
ABA
ABCBA
ABCDCBA

Pathik
15-03-2008, 04: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 ?


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
15-03-2008, 05:37 PM
Is it like Pascal Triangle ??

~Phenom~
15-03-2008, 05:56 PM
Should it be ?


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
15-03-2008, 06: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~
15-03-2008, 07:54 PM
^^Do not seem to work. Others please help, now that u know the right pyramid , please pour in ur code ....

Pathik
15-03-2008, 08:42 PM
#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~
15-03-2008, 09:00 PM
^^Thanx Buddy. :-)

redhat
19-03-2008, 05:49 PM
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.....