C++ Program to input a decimal number and print in Binary, Octal, and Hexadecimal form with inbuilt function itoa
This function is not defined in ANSI-C and is not part of C++, but is supported by some compilers.
#include <iostream>#include <stdlib.h>#include<iomanip>using namespace std;int main (){int i;char buffer [20];cout<<"Enter The Number : ";cin>>i;cout<<"------------------------------------------------------------"<<endl;itoa (i,buffer,10);cout<<setw(15)<<"Decimal : "<<buffer<<endl;itoa (i,buffer,16);cout<<setw(15)<<"Hexadicimal : "<<buffer<<endl;itoa (i,buffer,2);cout<<setw(15)<<"Binary : "<<buffer<<endl;itoa (i,buffer,8);cout<<setw(15)<<"Octal : "<<buffer<<endl;return 0;}
Syntax of the function itoa :
char * itoa ( int value, char * str, int base );
Thanks sir
ReplyDelete