C Program to Find Common Array Elements - Source Code, Output & Execution Flow

C Program to Find Common Array Elements

This tutorial explains c program to find common array elements with C source code, sample output, and step-by-step execution flow.

#include <stdio.h>
int main() {
    int a[] = {1, 2, 3, 4}, b[] = {3, 4, 5, 6};
    int i, j;
    printf("Common elements: ");
    for (i = 0; i < 4; i++)
        for (j = 0; j < 4; j++)
            if (a[i] == b[j]) printf("%d ", a[i]);
    return 0;
}
Common elements: 3 4

In this program, the input is read first when required, the core logic is applied step by step, and the final result is displayed using printf(). Follow the execution flow beside the code to understand how each statement contributes to the output.