Count Prime Numbers in 3D Array Dry Run in C

Count Prime Numbers in 3D Array is an interactive C dry run visualizer from the Multi D programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Count Prime Numbers in 3D Array Program Code

#include <stdio.h>
#include <stdbool.h>
bool isPrime(int n) {
    int i;
    if(n <= 1) return false;
    for(i = 2; i*i <= n; i++)
        if(n % i == 0) return false;
    return true;
}
int main() {
    int arr[2][3][4] = {2,3,4,5,6,7,8,9,10,11,12,13,
                        14,15,16,17,18,19,20,21,22,23,24,25};
    int primeCount = 0, i, j, k;
    
    for(i =0;i<2;i++)
        for(j =0;j<3;j++)
            for(k =0;k<4;k++)
                if(isPrime(arr[i][j][k]))
                    primeCount++;
    
    printf("Prime numbers: %d\n", primeCount);
    return 0;
}

View the complete Multi D programs page.

Program Console Count Prime Numbers in 3D Array Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.