How to print this ???
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 .... |
Re: How to print this ???
This pyramid structure we created in C & C++ :)
Do u want the same in those languages? |
Re: How to print this ???
[quote=KaranTh85;777731]This pyramid structure we created in C & C++ :)
Do u want the same in those languages?[/quote] Any language will do yaar, I just want the logic. U may give it to me in C/C++/Java... |
Re: How to print this ???
Ignoring the spaces, Shouldn't it be
A AA ABA ABBA ABCBA .... |
Re: How to print this ???
^^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.
|
Re: How to print this ???
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!:) |
Re: How to print this ???
^^ 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 :? |
Re: How to print this ???
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 [/code] |
Re: How to print this ???
[QUOTE=mehulved;777957]^^ 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 :?[/QUOTE] [QUOTE=FilledVoid;777988]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 [/code][/QUOTE] 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. |
Re: How to print this ???
Is it like Pascal Triangle ??
|
Re: How to print this ???
[quote=FilledVoid;777988]
Should it be ? [code] A ABA ABCBA ABCDCBA [/code][/quote] Yes, this is what I want , sorry for giving flawed one earlier. Can I please have the code now ???? |
Re: How to print this ???
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 [QUOTE] 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; } [/QUOTE] |
Re: How to print this ???
^^Do not seem to work. Others please help, now that u know the right pyramid , please pour in ur code ....
|
Re: How to print this ???
[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 [/code] |
Re: How to print this ???
^^Thanx Buddy. :-)
|
Re: How to print this ???
[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(); } } [/CODE] In Java..... |
| All times are GMT +5.5. The time now is 12:54 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.