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
"C" language developed by "Dennis Ritchie" at AT & T. his remarks are a) too general, too abstract b) could deal with only specific problems c) lost generality of BCPL and B restored d) no remarks
Explain goto?
why arguments can generally be passed to functions a) sending the values of the arguments b) sending the addresses of the arguments c) a & b d) none of the above
Tell me with an example the self-referential structure?
What is the difference between class and object in c?
Explain what is the purpose of "extern" keyword in a function declaration?
where are auto variables stored? What are the characteristics of an auto variable?
What is line in c preprocessor?
Why is sizeof () an operator and not a function?
a construct the"else" part of "if" statement contains anoth "if else" statement is called a) if-else b) else-if-else c) if-else-if-else d) chain if/if-else-if
What does stand for?
develop algorithms to add polynomials (i) in one variable
Differentiate between static and dynamic modeling.
How can you determine the maximum value that a numeric variable can hold?
What is the size of enum in bytes?