adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C and C++ to Convert Decimal to Hexadecimal number Using recursive function

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



                      Post a Comment

                      0 Comments