Thread: start var at 0 or 1

  1. #1
    Registered User
    Join Date
    Feb 2018
    Location
    San Diego, CA
    Posts
    123

    start var at 0 or 1

    Code:
    #include <stdio.h>
      
    int i, p;
    
    
    char letter_a = 'A';
    
    
    int main (void)
    {
    
    
            for (i = 0; i < 10; ++i)
            {
                    printf("%d. ", i);  // count 1 to 10
    
    
                    for (p = 0; p < 10 - i; ++p)
                    {
                            printf("%c", letter_a); // output num_0 p times
                    }
    
    
                    printf("\n");
            }
    
    
            return 0;
    }
    
    
    
    
    jamie@box6:~/june_2021$ ./a.out 
    0. AAAAAAAAAA
    1. AAAAAAAAA
    2. AAAAAAAA
    3. AAAAAAA
    4. AAAAAA
    5. AAAAA
    6. AAAA
    7. AAA
    8. AA
    9. A
    jamie@box6:~/june_2021$
    Please, which line of code would I edit to adjust the executed code to display start/end lines to begin or end at 0, 1 or 9 or 10?

    Code:
            for (i = 0; i < 10; ++i)

  2. #2
    Registered User
    Join Date
    Feb 2018
    Location
    San Diego, CA
    Posts
    123
    here this is the final program, with the format specifiers and the => operator

    Code:
    #include <stdio.h>
    
    
    char letter_a = 'A';
    
    
    int main (void)
    {
    
    
            for (int i = 1; i <= 10; ++i)
            {
                    printf("%2d. ", i);  // count 1 to 10
    
    
                    for (int p = 0; p <= 10 - i; ++p)
                    {
                            printf("%c", letter_a); // output num_0 p times
                    }
    
    
                    printf("\n");
            }
    
    
            return 0;
    }

    Enjoy...

  3. #3
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338

    Post

    start/end lines to begin or end at 0, 1 or 9 or 10?
    Code:
    #include <stdio.h>
      
    int i, p;
    char letter_a = 'X';
    
    int main (void) {
    
        int start = 5, finish = 15;
    
        for (i = start; i <= finish; ++i) {
            printf( "%d. ", i ); 
            for (p = 0; p <= finish - i; ++p) {
                printf( "%c", letter_a );
            }
            printf("\n");
        }
    
        return 0;
    }
    Last edited by Structure; 06-10-2021 at 07:29 AM.
    "without goto we would be wtf'd"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble start to start this C program
    By cool1995 in forum C Programming
    Replies: 1
    Last Post: 10-18-2016, 12:51 AM
  2. Does anyone know how to start this off?
    By Ashley246 in forum C++ Programming
    Replies: 2
    Last Post: 10-05-2011, 05:34 AM
  3. where do i start?
    By xixpsychoxix in forum Windows Programming
    Replies: 3
    Last Post: 03-30-2007, 12:25 AM
  4. where to start
    By brad.g in forum C++ Programming
    Replies: 4
    Last Post: 01-17-2006, 04:09 PM
  5. Where do I start?
    By RavUnRex in forum C Programming
    Replies: 14
    Last Post: 11-18-2005, 03:31 PM

Tags for this Thread