 # C Programming Code Examples

## C > Conversions Code Examples

### C Program to Convert the given Binary Number into Decimal

``` C Program to Convert the given Binary Number into Decimal - Take a binary number and store it in the variable j. - Initialize the variable decimal_val to zero and variable base to 1. - Obtain the remainder and quotient of the binary number. Store the remainder in the variable rem and override the variable j with quotient. - Multiply rem with variable base. Increment the variable decimal_val with this new value. - Increment the variable base by 2. - Repeat the steps 3, 4 and 5 with the quotient obtained until quotient becomes zero. - Print the variable decimal_val as output. #include <stdio.h> void main() { int j, binary_val, decimal_val = 0, base = 1, rem; printf("Enter a binary number(1s and 0s) \n"); scanf("%d", &j); /* maximum five digits */ binary_val = j; while (j > 0) { rem = j % 10; decimal_val = decimal_val + rem * base; j = j / 10 ; base = base * 2; } printf("The Binary number is = %d \n", binary_val); printf("Its decimal equivalent is = %d \n", decimal_val); } ```

C++ language Program to Implement Trie - Program demonstrates the implementation of Trie. Trie node base declaration. Trie node declaration. Trie class declaration. Insert trie node. Destroy trie. Trie traversal. Clustering

C++ Language Samples Separate Chaining - Internal method to test if a positive number is prime. Not an efficient algorithm and Internal method to return a 'prime number' at least as large as n. Assumes "n > 0". Insert item x into

C Program code to Multiply two Matrices - Read elements in two matrices and multiply them. Matrix multiplication program in C. How to multiply matrices in C programming. Input elements in first matrix from user and...

Find the First Occurrence of a Character in - C program to 'input any string' from user and find the 'first occurrence' of a given character in the string. Input string from user and store it in a variable say "str". Run a loop from start

C++ Codings Find the Maximum Subarray - Implement the 'naive method' to find the sub array having a maximum sum. The worst case time 'Complexity' of the algorithm is 'O(n*n)'. Take the input of the 'integer array'. Compare

Implement A Heuristic to Find the Vertex - Problem takes E edges as input and outputs vertex cover of the graph, implementing the following heuristic. There is no "Polynomial" time algorithm "invented up to date" to find

Singly Linked list Program Using functions - In C++, under the simplest form, each node is composed of data and a reference ('a link') to the next node in the sequence. This structure allows for efficient insertion or removal of the

C Language Sample Add Two Polynomials - Enrter the elements of the first poly. Unable to create memory. Enter the elements of the second poly. Printing the elements of the lists. The elements of the poly first are. The...