Thread: Help please

  1. #1
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751

    Help please

    I"m trying to have the output as discribed in my code however i seem to have the logic messed up
    Code:
    forget the fact that i haven't put it to uppercase yet, i'll do that later. The code seems to have the desired results in terms of the structure, but the characters are all wrong. Is there a math problem here?
    #include <stdio.h>
    int main(void){
    /* output   A
                BA
                CBA
                DCBA
                EDCBA  */
    
     /* output is structure i want but not letters */
     int r,c;
    
     for(r = 0; r <= 5; r++){
        for (c = 'a'; c<=('a' + r); c++){
           printf("%c", r - c);  /* this is correct algorithm for the structure */
        }
         printf("\n");
    
      }
      getchar();
      return 0;
      }
    
    P.s. if the color bothers you guys, i was just testing out the vb code, won't do it again
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Close:
    Code:
    #include <stdio.h>
    
    int main ( void )
    {
      int r, c;
    
      for ( r = 0; r < 5; r++ ) {
        for ( c = 'A' + r; c >= 'A'; c-- )
          printf ( "%c", c );
        printf ( "\n" );
      }
    
      return 0;
    }
    My best code is written with the delete key.

  3. #3
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Thanks alot prelude. I hope your not as beautiful as your inteligent that would be a real lethal combination.

    Now to go see what i did wrong.
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

Popular pages Recent additions subscribe to a feed