1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>

// Nested loops decrease the scalability, because as the size of the problem
// increases, the time to run your program increases "quadratically".

int main(int argc, const char *argv[]) {
    for( int i = 0; i < 5000000; i++ ) {
        for( int j = 0; j < 7000000; j++ ) {
            printf( "ABC" );  // will result in a while loop that exec's 4 times
            printf( "XYZ" );  // will result in a while loop that exec's 4 times
        }
    }
    return EXIT_SUCCESS;
}

int main_alternate(int argc, const char *argv[]) {
    for( int j = 0; j < 7000000; j++ ) {
        printf( "ABC" );  // will result in a while loop that exec's 4 times
    }
    for( int i = 0; i < 5000000; i++ ) {
        printf( "XYZ" );  // will result in a while loop that exec's 4 times
    }
    return EXIT_SUCCESS;
}

© Copyright 2016 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.