+= array_b[i]; int average_b = sum_b / 4; The two loops can be rewritten as the single function: int calc_average_of_four(int* array) { int sum = 0; for (int i = 0; i < 4; i++) sum += array[i]; return sum / 4; } or, usually preferably, by parameterising the number of elements in the array. Using the above function will give source code that has no loop duplication: extern int array1[]; extern int array2[]; int average1 = calc_average_of_four(array1); int average2 = calc_average_of_four(array2); Note that in this trivial case, the compiler may choose to inline both calls to the function, such that the resulting machine code is identical for both the duplicated and non-duplicated examples above. If the function is not inlined, then the additional overhead of the function calls will probably take longer to run (on the order of 10 processor instructions for most high-performance languages). Theoretically, this additional time to run could matter. See also Abstraction principle (programming) Anti-pattern Data deduplication Don't repeat yourself (DRY) List of tools for static code analysis Redundant code Rule of three (computer programming) References External links The University of Alabama at Birmingham: Code Clones Literature Finding duplicate code in C#, VB.Net, ASPX, Ruby, Python, Java, C, C++, ActionScript, or XAML Articles with example C code Software metrics Source code