i want to show output like this

A B C D E F G F E D C B A
A B C D E F     F E D C B A
A B C D E          E D C B A
A B C D                D C B A
A B C                       C B A
A B                             B A
A                                   A

i write a program to out put this but it contaions some error
please help me to solve this problem

#include<stdio.h>
#include<conio.h>
void main(void)
{
int row=0,col=0,sp=0,a=65,b,mid=1,st=71,end=64;
clrscr();
for (row=1;row<=7;row++)
{
	for(col=65;col<=st;col++)
	{
	printf("%c ",col);
	}
	for(b=1;b<mid;b++)
	{
	printf("  ");
	}
	for(sp=71;sp>end;sp--)
	{
	printf("%c ",sp);
	}

st--;
mid+=2;
a++;
end++;
printf("\n\n");
}
getche();
}

it output is

A B C D E F G G F E D C B A
A B C D E F        G F E D C B
A B C D E              G F E D C
A B C D                    G F E D
A B C                           G F E
A B                                 G F
A                                        G
A B C D E F G G F E D C B A
A B C D E F        G F E D C B
A B C D E              G F E D C
A B C D                    G F E D
A B C                           G F E
A B                                 G F
A                                        G

why it donot show spaces between this output

A B C D E F G F E D C B A
A B C D E F __F E D C B A
A B C D E _____E D C B A
A B C D________ D C B A
A B C____________C B A
A B_______________ B A
A __________________A
where (_) is space
i want to print this please help me i am new one

A B C D E F G G F E D C B A
A B C D E F        G F E D C B
A B C D E              G F E D C
A B C D                    G F E D
A B C                           G F E
A B                                 G F
A                                        G

why it donot show spaces between this output

The problem is in vBulletin -- added code tags to correct the problem.

From my first glance at your problem, it would appear that the first line is a 'special case' as it does not have spaces at all (which would work as the zero spaces case) but the 'left side' and the 'right side' are not mirror images of each other. Someone has to get the G printed.

What about breaking it down into left / G / right for the first line and then left / spaces / right for the remaining lines.

The reason all of your right sections start with G is because you told them to here: for(sp=71;sp>end;sp--) maybe the 71 should be 71 - row or something?

The reason the right sections don't all go down to A (like you say they should) is because you're incrementing end inside the loop on line 25. If the right sections should always go to A don't change end.

#include<stdio.h>
#include<conio.h>

int main(void)
{
int row=0,col=0,sp=0,b,mid=1,st=71,end=64;
//clrscr();
int column_num=0;
for (row=1;row<=7;row++)
{
	for(col=65;col<=st;col++)
	{
	printf("%c ",col);
	}
 for(b=1;b<mid;b++)
	{
	printf("  ");
	}
	for(sp=70;sp>end;sp--)
	{
	printf("%c ",sp-column_num);//start with less symbol

	}
 
st--;
mid+=2;

column_num++;
end++;
printf("\n\n");
}
getche();
return 1;
}

Your code is absolutely unreadable but I managed to noticed smth. First you don't start to wrtite another row with another symbol. My variable column_num does this. Previous message said my second point. Ask question if you want.

@zhelih

Your english is barely readable, and the above post was your first post in this thread, what was your second point?

@asharrajpoot

I had an idea for another way to code the output. What if you built a string that contained the proper first line. (I'll build it manually, but you should probably use a loop.)

char masterline[80] = "A B C D E F G F E D C B A";

Then to print the table as you wanted:

Then you could walk through the row, outputting characters. If the character in the string is less than a limit (we will cover the limit ina second) you output the character, otherwise you output a space.

For the 1st row, print all characters <= 'G' (which would be all of them)
For the 2nd row, print all characters <='F' (all but the G)
For the 3rd row, print all characters <= 'E'
...
For the last row, print all characters <= 'A'

Would that be any easier?

The proposed algorithm would probably consume more CPU than what you're doing now, but I also suspect that both will run so fast you won't notice.

i have do some modifiaction so try this....

#include<stdio.h>
#include<conio.h>
void main(void)
{
int row=0,col=0,sp=0,a=65,b,mid=1,st=71,end=64;
clrscr();

for (row=1;row<=7;row++)
{
	for(col=65;col<=st;col++)
	{
		printf("%c ",col);

	}

	for(b=1;b<mid;b++)
	{
		printf("  ");

	}

	for(sp=col-1;sp>end;sp--)

	{

		printf("%c ",sp);

	}

	st--;
	mid+=2;
	a++;
	/*end++;*/

	printf("\n\n");
}

getche();

}
void Pyr(int N)
{
    if (N >= 0 && N < 26) {
        const char* z2a = "ZYXWVUTSRQPONMLKJIHGFEDCBA" + (26 - N);
        int i, j, d, dist, mid = N+N - 2, n = 4*N - 1;
        for (i = 0; i < N; ++i) {
            dist = i + i - 1;
            for (j = 0; j < n; ++j) {
                d = abs(j-mid);
                putchar((j&1)||d < dist
                    ?' ':z2a[d>>1]);
            }
            putchar('\n');
        }
    }
}
int main()
{
    Pyr(7);
    return 0;
}

I have written some rough code, please modify according to your requirement:

1) For pattern
A B C D E F G F E D C B A
A B C D E F __F E D C B A
A B C D E _____E D C B A
A B C D________ D C B A
A B C____________C B A
A B_______________ B A
A __________________A

int main(void)
{
    char ch;
    int i=0,j=0,k=0,l=0,h=0,m=0;

    printf("\n Enter a CAPS charachter: ");
    scanf("%c",&ch);
    for(k=0;k<=ch-65;k++)
    {
        for(i=65;i<=ch-k;i++)
            printf("%c ",(char)i);
        if(k>0)
        {
            h = 4*k;
            for(l=0;l<h-2;l++)
            printf(" ");
        }
        if(k>1)
        m = k-1;
        for(j=ch-1-m;j>=65;j--)
            printf("%c ",(char)j);
        printf("\n");
    }
    return 0;
}

2. For pattern:
A B C D E F G F E D C B A
A B C D E F___F E D C B A
A B C D E_______E D C B A
A B C D___________D C B A
A B C_______________C B A
A B___________________B A
A_______________________A

int main(void)
{
    char ch;
    int i=0,j=0,k=0,l=0,h=0,m=0;

    printf("\n Enter a CAPS charachter: ");
    scanf("%c",&ch);
    for(k=0;k<=ch-65;k++)
    {
        for(i=65;i<=ch-k;i++)
            printf("%c ",(char)i);
        if(k>0)
        {
            h = 5*k;
            for(l=0;l<h-1;l++)
            printf(" ");
        }
        if(k>1)
        m = k-1;
        for(j=ch-1-m;j>=65;j--)
            printf("%c ",(char)j);
        printf("\n");
    }
    return 0;
}

I hope you got the answers......If yes, then please acknowledge and help us closing the thread....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.