• CONTEST ALERT - Experience the power of DDR5 memory with Kingston Click for details

How to print this ???

Status
Not open for further replies.

~Phenom~

The No.1 Stupid
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 ....
 
OP
~Phenom~

~Phenom~

The No.1 Stupid
^^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

Right off the assembly line
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

18 Till I Die............
^^ 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

Who stole my Alpaca!
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

Google Bot
^^ 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.
 

ring_wraith

=--=l33t=--=
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;
}
 
OP
~Phenom~

~Phenom~

The No.1 Stupid
^^Do not seem to work. Others please help, now that u know the right pyramid , please pour in ur code ....
 

Pathik

Google Bot
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
 

redhat

Mad and Furious
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.....
 
Status
Not open for further replies.
Top Bottom