Search C Program

Loading...

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;
}

14 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 anyone tell me how to write this code using cout statements??

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

    ReplyDelete
  7. 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
  8. this program does not work

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

    ReplyDelete
  10. Simple for above-->

    #include
    int main()
    { int i;

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

    ReplyDelete