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 an auto keyword in c?
main() { printf("\n %d %d %d",sizeof('3'),sizeof("3"),sizeof(3)); }
Can we initialize extern variable in c?
Write a code to reverse string seperated by spaces i/p str=India is my country o/p str=aidnI si ym yrtnuoc After writing code, optimize the code
how to do in place reversal of a linked list(singly or doubly)?
Explain how to reverse singly link list.
A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles
What is the relation between # and include<stdio.h>
Dear Sir, we are required the bubble sorting programs Regs Prem
can we have joblib in a proc ?
main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }
who will call your main function in c under linux?