Find numbers expressible as sum of two primes (for loop) Dry Run in C

Find numbers expressible as sum of two primes (for loop) is an interactive C dry run visualizer from the Nested 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.

Find numbers expressible as sum of two primes (for loop) Program Code

#include <stdio.h>
int isPrime(int n) { int i;
    if(n < 2) return 0;
    for(i = 2; i * i <= n; i++)
        if(n % i == 0) return 0;
    return 1;
}

int main() {
    int start, end, num, i;
    printf("Enter range (start end): ");
    scanf("%d %d", &start, &end);
    
    printf("Numbers expressible as sum of two primes:\n");
    
    for(num = start; num <= end; num++) {
        if(num < 4) continue;  // Smallest sum of two primes is 4 (2+2)
        
        int found = 0;
        for(i = 2; i <= num/2; i++) {
            if(isPrime(i) && isPrime(num - i)) {
                printf("%d = %d + %d\n", num, i, num - i);
                found = 1;
                break;
            }
        }
    }
    return 0;
}

View the complete Nested programs page.

Program Console Find numbers expressible as sum of two primes (for loop) Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.