Write a C program to convert an integer into a binary
string?
Answer / vadivelt
#include<stdio.h>
char *IntToBinString(int no);
main()
{
int no;
printf("ENTER THE NO: ");
scanf("%d",&no);
printf("\nBINARY O/P STRING:\n%s",IntToBinString(no));
getch();
}
char *IntToBinString(int no)
{
char *ptr;
int i, size;
size = sizeof(int)*8;
ptr = (char *)malloc(sizeof(int)*8);
for(i = size - 1; i >= 0; i--)
{
if(no >> i & 0x01)
{
*ptr++ = 49;
}
else
{
*ptr++ = 48;
}
}
*ptr = '\0';
return (ptr - size);
}
| Is This Answer Correct ? | 9 Yes | 3 No |
What is a built-in function in C?
What is the meaning of this decleration? unsigned char (*pArray[10][10]); please reply.
How can I find leaf node with smallest level in a binary tree?
Which built-in library function can be used to match a patter from the string?
What is malloc() function?
how to implement stack work as a queue?
why division operator not work in case of float constant?
What is scanf () in c?
how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12
Write a C program to read the internal test marks of 25 students in a class and show the number of students who have scored more than 50% in the test. Make necessary assumptions.
What is volatile variable in c?
Differentiate between the expression “++a” and “a++”?