Program Console Vignaankosh.com
Execution Panel
Console is empty.
R14 Count occurrences of an element (Recursion) is an interactive C dry run visualizer from the Recursion 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 countOccurrences(int arr[], int n, int target, int index) {
if(index == n) {
return 0;
}
int countFromRight = countOccurrences(arr, n, target, index + 1);
int currentCount;
if(arr[index] == target) {
currentCount = 1;
} else {
currentCount = 0;
}
int totalCount = currentCount + countFromRight;
return totalCount;
}
int main() {
int arr[] = {8, 3, 8, 3, 9, 8, 2};
int target = 8;
int cnt = countOccurrences(arr, 7, target, 0);
printf("%d appears %d times\n", target, cnt);
return 0;
}