Page Rank Checker

Saturday 5 July 2014

Produce Given Pattern With A, B, C, D, E, F, G Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to produce the following 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

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int i, j, l;
    for(j=0,l=72;j<=6;j++,l--)
    {
        for(i=65;i<=71;i++)
        {
            if(i<l)
            printf("%c ",i);
            else
            printf("  ");
            if(i==71)
            {
                i--;
                for(;i>=65;i--)
                {
                    if(i<l)
                    printf("%c ",i);
                    else
                    printf("  ");
                }
                break;
            }
        }
        printf("\n");
    }
    getch();
}