Thread: Pattern Printing

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    24

    Pattern Printing

    I want to print the following pattern,

    ABCDEFGH
    ABC FGH
    AB GH
    A H


    I wrote the following programmfor it but It ends up in an Infinite Loop. Someone please help me out.

    Code:
    #include <stdio.h>
    #include <conio.h>
    int main()
    {
    int count1, count2,num1,num2,num3,num4,m,n; clrscr(); for(m=4;m>=0;m--) {
    for(num1=65;num1<65+m;num1++) {
    printf("%c",num1);
    } for(count1=0;count1<=((4-m)*2);count1=count1+2) {
    while(count1>0) {
    printf(" ");
    }
    } for(num2=(74-m);num2<=73;num2++) {
    printf("%c",num2);
    } printf("\n");
    } getch(); return 0;
    }
    Last edited by sunny`; 03-18-2012 at 09:12 PM.

  2. #2
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Code:
    while(count1>0) {
    printf(" ");
    }
    You need to decrement count1.

    EDIT: Aside from that, you don't want a while loop there, change it too an if statement instead.
    Last edited by camel-man; 03-18-2012 at 08:52 PM.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    24
    ok, This one Worked. Thanks Alot.


    Code:
    #include <stdio.h>
    #include <conio.h>
    int main()
    {
    int count1, count2,num1,num2,num3,num4,m,n; clrscr(); for(m=4;m>=0;m--) {
    for(num1=65;num1<65+m;num1++) {
    printf("%c",num1);
    } for(count1=0;count1<=((4-m)*2);count1=count1+1) {
    if(count1>0) {
    printf(" ");
    }
    } for(num2=(73-m);num2<73;num2++) {
    printf("%c",num2);
    } printf("\n");
    } getch(); return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Pattern Help
    By Lestat in forum C++ Programming
    Replies: 10
    Last Post: 10-24-2007, 02:05 PM
  2. need help printing this pattern
    By Blimpy325 in forum C Programming
    Replies: 4
    Last Post: 03-04-2006, 06:40 AM
  3. (pattern *) pat & pattern * pat
    By siubo in forum C Programming
    Replies: 1
    Last Post: 04-08-2003, 10:03 PM
  4. Printing a pattern correctly???
    By Basia in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 04:34 PM
  5. Printing a Pattern of Stars
    By ProgrammingDlux in forum C++ Programming
    Replies: 13
    Last Post: 03-01-2002, 08:38 AM