Write a C program to convert an integer into a binary
string?
Answer Posted / 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 |
Post New Answer View All Answers
When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?
How many bytes are occupied by near, far and huge pointers (dos)?
while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above
Can we compile a program without main() function?
Is swift based on c?
What are valid operations on pointers?
What is %g in c?
Explain what is the difference between #include and #include 'file' ?
Why can't I perform arithmetic on a void* pointer?
What is c language used for?
What are the two forms of #include directive?
By using C language input a date into it and if it is right?
Explain the ternary tree?
A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none
What is structure pointer in c?