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 |
Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should not use big integers and exponential functions)
2 Answers HCL, IBM, Satyam, Vimal, Vimukti Technologies,
what is the diference between pointer to the function and function to the pointer?
write a programme that inputs a number by user and gives its multiplication table.
can we have joblib in a proc ?
what is diffrence between string and character array?
how to write a program which adds two numbers without using semicolon in c
Explain #pragma statements.
What is the difference between c and python?
Write a program or provide a pseudo code to flip the 2nd bit of the 32 bit number ! (Phone Screen)
Write a factorial program using C.
What Is The Difference Between Null And Void Pointer?
C language questions for civil engineering