Search C Program | nimishsoft@gmail.com

Alphabet Pattern - 1

A
AB
ABC
ABCD
ABCDE


#include <stdio.h>

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

    return 0;
}

20 comments:

  1. the above code is giving error during compiling..... plllzz help.

    ReplyDelete
    Replies
    1. it is working fine, check this link http://codepad.org/cXIdAfs3

      Delete
  2. how can you put a character without declaring it. You printed a character without using in as variable..

    ReplyDelete
    Replies
    1. printf("%c",'A' + j-1);
      'A' is a character literal and has its ASCII Value, when you add 1 in 'A' it becomes 'B'

      Delete
  3. #include
    #include
    void main()
    { char j;
    int i;
    clrscr();
    for(i=0;i<5;i++){
    for(j=65;j<=65+i;j++)
    printf("%c", j);
    printf("\n");
    }
    getch();
    }

    ReplyDelete
  4. how do i write it in couyt statement insted of printf

    ReplyDelete
  5. can u pls. explain ASCII

    ReplyDelete
  6. can anyone tell me how to write this code using cout statements??

    ReplyDelete
  7. guys in java language how can i print any one plz help.

    ReplyDelete
  8. you can go for;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<=i;j++)
    {
    if(i>=j)
    {
    printf("%c",'A'+j-1);
    }
    else
    {
    continue;
    }
    }
    printf("/n ");
    .
    .
    .

    ReplyDelete
  9. this program does not work

    ReplyDelete
  10. this code is not working, it goes for infinite loop.

    ReplyDelete
  11. Simple for above-->

    #include
    int main()
    { int i;

    for(i=1;i<=5;i++)
    {
    printf(" %.*s\n",i,"ABCDE");
    } return 0;
    }

    ReplyDelete
  12. A B C D 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

    ReplyDelete
  13. COULD YOU PLEASE EXPLAIJ THIS

    ReplyDelete
  14. you can use this insted of this to
    #include "stdio.h"
    void main()
    {
    int i,j,n=64,s;
    for(i=1;i<=4;i++)
    {
    for(s=1;s<=4-i;s++)
    {
    printf(" ");
    }
    for(j=n+i;j>=65;j--)
    {
    printf("%c",j);
    }
    printf("\n");
    }
    }

    ReplyDelete