Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Letter Pyramid

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Can anyone help???

This is what I have so far, but I can't seem to make it right. The output should be:

A
ABA
ABCBA
ABCDCBA
ABCDEDCBA

When the Letter 'E' is input. Any help be appreciated.
Cliff

#include <iostream>
#include <string>
#include <cctype>

using namespace std;

void Inp(int, char);
void Outp(int, char);

int main()

{

char let = 'A';
int num = 0;

Inp(num, let);
return 0;
}

//**********************************************************
//**********************************************************

void Inp(/* inout */ int num,
/* inout */ char let)
{
do
{
cout <<&quot;Please enter a letter: &quot;;
cin >> let;
cout << &quot;\n\n&quot;;

if (let < 'A' || let > 'z')
cout <<&quot;Invalid Letter!!! Try Again \n\n\a&quot;;
} while (let < 'A' || let > 'z');

Outp (num, let);
}

//**********************************************************
//**********************************************************

void Outp(/* inout */ int num,
/* in */ char let)
{

char a, b, c='A', d, e='Z';

for (a='A';a<=let;a++)
{
for (b='A';b<e;b++)
cout<<&quot; &quot;;

for (d='A';d<=c;d++)
cout<<d;
cout<<&quot;\n&quot;;
c++;
e--;
}

}
 
#include <memory.h>

void Print(char aChar){
char szBuf[100];
if (aChar <'A' || aChar >'Z') return;
int nCount = aChar - 'A'; // get the length of sequence
szBuf[2*nCount +1] = '\0'; // set the buffer null terminator

for (char i = 'A'; i<=aChar; i++){
memset(szBuf,' ',2*nCount + 1); // clear the buffer with spaces
int nOffset = aChar - i; // get the offset
for (char j='A';j<i;j++)
szBuf[nOffset+j-'A'] = szBuf[nCount*2 - (j -'A')- nOffset] = j;
szBuf[nCount] = i; // middle one
printf(&quot;%s\n&quot;,szBuf);
}
}

void main(){
Print('L');
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top