Search C Program

Alphabet Pattern - 5

ABCDE
ABCD
ABC
AB
A


#include <stdio.h>

int main()
{
    int i, j;
    for(i=5;i>=1;i--)
    {
        for(j=1;j<=i;j++)
        {
            printf("%c",'A' + j-1);
        }
        printf("\n");
    }

    return 0;
}


4 comments:

  1. Replies
    1. it is adding the numeric in ASCII values of 'A'

      Delete
  2. what code we will write to get the same output without using loop....
    but by using goto or of else statement...???

    ReplyDelete
  3. #include
    #include
    main()
    {
    int n,i,l;
    printf("enter the number of lines :");
    scanf("%d",&n);
    for(l=1;l<=n;l++)
    {
    for(i=1;i<=n+1-l;i++)
    {

    printf("%c",'A'+i-1);

    }
    printf("\n");
    }
    getch();
    }

    ReplyDelete