Enquiry on generation of number pattern using nested for loops

This is a discussion on Enquiry on generation of number pattern using nested for loops within the C Programming forums, part of the General Programming Boards category; May I have your advice on the generation of the following number pattern using nested for loops? Thank you so ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    2

    Question Enquiry on generation of number pattern using nested for loops

    May I have your advice on the generation of the following number pattern using nested for loops? Thank you so much ~

    2 4 6
    7 9 11
    12 14 16
    17 19 21


    But I can only figure out

    2 4 6
    3 5 7
    4 6 8
    5 7 9

    and below is the code:

    Code:
    #include <stdio.h>
    int main() {
            int i, j;
    
            for (i=0; i<4; i++){
                    for (j=2; j<7; j=j+2){
                    printf("%d ", i+j);
            }
            printf("\n");
            }
            getchar();
            return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,457
    Why are you only incrementing i by one each time. How much does each number change from row to row?

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    Notice that the first number in each row differs from the first number of the next row by 5. Notice that each number of each row differs from the next number in the same row by 2.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Dec 2010
    Posts
    2
    I got it. Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 12-23-2009, 12:55 PM
  2. Replies: 5
    Last Post: 10-05-2009, 10:21 AM
  3. Working with Nested "Switch Multiple-Selection"
    By MAV_DevWantB in forum C Programming
    Replies: 5
    Last Post: 09-18-2009, 08:05 AM
  4. Desperate for help - ugly nested if
    By baseballkitten in forum C Programming
    Replies: 4
    Last Post: 11-19-2001, 02:56 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21