 # C Programming Code Examples

## C > Conversions Code Examples

### Program to Convert Roman Number to Decimal Number

``` Program to Convert Roman Number to Decimal Number - Take a roman number as input and store it in the array roman_Number. - In the function digit(), define the value of each digit of the roman number inside the switch statement and return the same. - Using while statement access each digit of the input number. - Firstly check if the current roman digit's value is less than zero. If it is, then print the output as "Invalid roman digit". - If not, then check if the value of current roman digit is greater or equal to its next digit's value. If it is, then increment the variable number with the value of current roman digit. - Otherwise, subtract the value of current roman digit from the value of its next roman digit and increment the variable number with the obtained value. - Print the variable number as output. #include<stdio.h> #include<string.h> int digit(char); int main(){ char roman_Number; int j=0; long int number =0; printf("Enter any roman number (Valid digits are I, V, X, L, C, D, M): \n"); scanf("%s",roman_Number); while(roman_Number[j]){ if(digit(roman_Number[j]) < 0){ printf("Invalid roman digit : %c",roman_Number[j]); return 0; } if((strlen(roman_Number) -j) > 2){ if(digit(roman_Number[j]) < digit(roman_Number[j+2])){ printf("Invalid roman number"); return 0; } } if(digit(roman_Number[j]) >= digit(roman_Number[j+1])) number = number + digit(roman_Number[j]); else{ number = number + (digit(roman_Number[j+1]) - digit(roman_Number[j])); j++; } j++; } printf("Its decimal value is : %ld",number); return 0; } int digit(char c){ int value=0; switch(c){ case 'I': value = 1; break; case 'V': value = 5; break; case 'X': value = 10; break; case 'L': value = 50; break; case 'C': value = 100; break; case 'D': value = 500; break; case 'M': value = 1000; break; case '\0': value = 0; break; default: value = -1; } return value; } ```

C++ Program to Implement Vector in STL - C++ code to Implement Vector in STL. Insert element into the vector. Delete last element of the vector. "Size of the vector". Display by index. "Dislplay by iterator". Clear the vector

C++ Implement Stack using Two Queues - This C++ program implements a "stack data" structure using two queue data structures. A stack data structure foolows the principle of LIFO(last element in first element out). Enter

Inputs Few Numbers Performs Merge Sort - C program, using recursion, 'Performs Merge' sort. A Merge Sort is a sorting algorithm with 'Complexity of O(nlogn)'. It is used for sorting numbers, structure, files. Perform Merge Sort

C++ Programming Array Sort Bubble Sort - To sort an array in ascending order by bubble sort in C++ language, you have to ask to user to enter the array size then ask to enter array elements, start sorting the array elements by

Find Maximum Minimum using Functions - First give a meaningful name to our function. Say max() function is used to find maximum between two numbers. Second, we need to find maximum between two numbers. And

Strrchr searches the string in reverse order - 'StrrChr' is similar to the function 'StrChr', the only difference is that it searches the string in "Reverse Order", would have understood why we have extra r in 'strrchr', yes you guessed it

Read an Array and Search for an Element - C code accept an array of N elements and a key to search. If the search is successful, it displays "Successful Search". Otherwise, a message "UNSUCCESSFUL SEARCH" is...

C Code Traverse the Tree Non-Recursively - C language code, using iteration, searches for a given node in a tree. The tree we have used is the binary search tree. A binary search tree follows a concept of nodes whose numbers...