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 |
Can you please explain the difference between syntax vs logical error?
Identify the correct argument for the function call fflush () in ANSI C: A)stdout B)stdin C)stderr D)All the above
main() { printf(5+"Vidyarthi Computers"); }
How many types of linked lists what are they? How many types of data structures?
18 Answers BSNL, Pivotal Software,
Explain how can you tell whether two strings are the same?
declare afunction pointer to int printf(char *)?
Famous puzzles which are generally asked by companies during interviews ?
Is c pass by value or reference?
program to find out date after adding 31 days to a date in the month of febraury also consider the leap year
what is ans for this scanf(%%d",c);
which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +
What is anagram in c?