#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    67
    Rep Power
    0

    Smile C program to print pattern


    hi guys i want to print this pattern


    http://pastebin.com/mrcjWzAr

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

    void main()

    {
    char i,j,k,c,d;
    int a,b,n;

    for(a=0;a<=6;a++)
    {
    //for(n=1;n<=6;n++)
    for(b=1;b<=2*b;b++)
    {
    for(c='G';c>='A';c--)
    {
    for(d='A';d<='G';d++)
    {
    printf("%c",d);
    }
    printf("%c",c);
    }
    printf(" ");
    }

    printf("\n");

    }


    getch();
    }

    but my program runs into infinite loop..
    i find printing patterns very hard any suggestions?
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,387
    Rep Power
    1871
    > for(b=1;b<=2*b;b++)
    Perhaps you should stop moving the goal-posts.
    b <= 2
    becomes
    b <= 4 (when b is 2)
    becomes
    b <= 6 (when b is 3)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo