Program Console Vignaankosh.com
Execution Panel
Console is empty.
Find Smith numbers in a range (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.
#include <stdio.h>
int main() {
int start, end, num, i, factor;
printf("Enter range (start end): ");
scanf("%d %d", &start, &end);
printf("Smith numbers between %d and %d:\n", start, end);
int found = 0;
for(num = start; num <= end; num++) {
// Check if prime inline
int is_prime = 1;
if(num < 2) is_prime = 0;
for(i = 2; i * i <= num; i++) {
if(num % i == 0) { is_prime = 0; break; }
}
if(is_prime) continue; // Smith numbers must be composite
// Sum of digits of num inline
int sumDigits = 0;
int temp_digits = num;
while(temp_digits != 0) {
sumDigits += temp_digits % 10;
temp_digits /= 10;
}
int sumFactorsDigits = 0;
int temp = num;
for(factor = 2; factor <= temp; factor++) {
while(temp % factor == 0) {
// Sum of digits of factor inline
int factor_temp = factor;
int sum_factor_digits = 0;
while(factor_temp != 0) {
sum_factor_digits += factor_temp % 10;
factor_temp /= 10;
}
sumFactorsDigits += sum_factor_digits;
temp /= factor;
}
}
if(sumDigits == sumFactorsDigits) {
printf("%d ", num);
found++;
}
}
printf("\nTotal Smith numbers: %d\n", found);
return 0;
}