Program in C and C++ to Convert Decimal to Hexadecimal number Using recursive function
C Program
#include<stdio.h> void decToHexa(int dec){ int temp; if(dec == 0) return; decToHexa(dec / 16); temp = (temp = dec % 16 ) >= 10 ? temp + 55 : temp + 48; printf("%c",temp); } int main(){ int n; printf("Enter decimal number :- "); scanf("%d",&n); printf("Hexadecimal : "); decToHexa(n); return 0; }
C++ Program
#include<iostream> using namespace std; void decToHexa(int dec){ int temp; if(dec == 0) return; decToHexa(dec / 16); temp = (temp = dec % 16 ) >= 10 ? temp + 55 : temp + 48; cout<<(char)temp; } int main(){ int n; cout<<"Enter a decimal number :- "; cin>>n; cout<<"Hexadecimal : "; decToHexa(n); return 0; }
Output :-
Related Programs
- Program in C & C++ to print the binary equivalent 1 to nth number.
- Program in C++ to Convert Binary to Decimal number Using Function
- Program in C to convert decimal into octal number.
- Program in C++ to Convert Hexadecimal to Decimal number Using Function
- Program in C++ to Convert Decimal to Hexadecimal number Using Function
- Program in C to Convert Decimal to Binary number.
- Program in C to print the binary equivalent 1 to nth number.
- Program in C and C++ to Convert Decimal to Binary number Using recursive function
- Program in C and C++ to Convert Binary to Decimal number Using recursive function
- Program in C and C++ to Convert Decimal to Octal number Using recursive function
- Program in C and C++ to Convert Octal to Decimal number Using recursive function
- Program in C and C++ to Convert Decimal number to Binary, Octal and Hexadecimal number Using recursive function
0 Comments