 # C Programming Code Examples

## C > Recursion Code Examples

### Count the Number of Occurrences of an Element in the Linked List using Recursion

``` Count the Number of Occurrences of an Element in the Linked List using Recursion This C Program uses recursive function & finds the occurrence for an element in an unsorted list. The user enters the element need to be counted. #include <stdio.h> void occur(int [], int, int, int, int *); int main() { int size, key, count = 0; int list; int j; printf("Enter the size of the list: "); scanf("%d", &size); printf("Printing the list:\n"); for (j = 0; j < size; j++) { list[j] = rand() % size; printf("%d ", list[j]); } printf("\nEnter the key to find it's occurence: "); scanf("%d", &key); occur(list, size, 0, key, &count); printf("%d occurs for %d times.\n", key, count); return 0; } void occur(int list[], int size, int index, int key, int *count) { if (size == index) { return; } if (list[index] == key) { *count += 1; } occur(list, size, index + 1, key, count); } ```

C Find Volume & Surface Area of Cylinder - This C Program code calculates volume and surface area of cylinder. The formula used in this C Program 'Surface_area' = 2 * Pi * r * (r + h) & Volume = Pi * r * r * h where Pi = 22/7.

Simple Calculator using Switch Statement - This C Program takes an arithmetic operator +, -, *, / and two operands from the user and Performs the Calculation on the 2 operands depending upon the operator entered by the

Multiply Two Matrix by Multi Dimensional - In this program, "enter the size "of 2 matrix at first. To multiply two matrices, the number of columns of first matrix should be equal to the "number of rows" to second matrix. C++ Code

Convert Binary Tree into Singly Linked List - C program converts a binary tree into a singly Linked List by Breadth first search algorithm. We use this algorithm for Traversing Level by Level. Structure type to point to the nodes of

Code Checks Even or Odd using Functions - Program input a number from user and check whether given number is Even or Odd using functions. Declare function to find even odd. First give a meaningful name to our function,

C Codes Implement Recalibrate Command - Check whether the FDC is ready. Read status of main status register. Check whether FDC is ready. Input the command parameters. Enter command parameters. Check the status of...

Sample Implements Sieve of Eratosthenes - C++ program sample to implement Sieve of Eratosthenes. Program initializes an integer array with all the "elements initialized" to 0. Then The Algorithm follows where the each

Computing The Volume of A Tetrahedron - Program to finds the volume of tetrahedron. Call the four vertices of the tetrahedron (a, b, c), (d, e, f), (g, h, i), and (p, q, r). Now create a 4-by-4 matrix in which the coordinate triples