Question
The itoa function can convert an integer in decimal, octal or hexadecimal form to a string.
Answer: Option A
/* itoa() example */
#include<stdio.h>
#include <stdlib.h>
int main ()
{
int no;
char buff [50];
printf ("Enter number: ");
scanf ("%d",&no);
itoa (no,buff,10);
printf ("Decimal: %s\n",buff);
itoa (no,buff,2);
printf ("Binary: %s\n",buff);
itoa (no,buff,16);
printf ("Hexadecimal: %s\n",buff);
return 0;
}
Output:
Enter a number: 1250
Decimal: 1250
Binary: 10011100010
Hexadecimal: 4e2
Was this answer helpful ?
itoa() takes the integer input value input and converts it to a number in base radix. The resulting number a sequence of base-radix digits.
Example:
/* itoa() example */
#include<stdio.h>
#include <stdlib.h>
int main ()
{
int no;
char buff [50];
printf ("Enter number: ");
scanf ("%d",&no);
itoa (no,buff,10);
printf ("Decimal: %s\n",buff);
itoa (no,buff,2);
printf ("Binary: %s\n",buff);
itoa (no,buff,16);
printf ("Hexadecimal: %s\n",buff);
return 0;
}
Output:
Enter a number: 1250
Decimal: 1250
Binary: 10011100010
Hexadecimal: 4e2
Was this answer helpful ?
More Questions on This Topic :
Question 1.
Is standard library a part of C language?
....
Question 8.
What will function gcvt() do?
....
Submit Solution