how to find the binary of a number?

Answer Posted / alle balraj

void main()
{
int i,n,p=0,j;
int a[10];
clrscr();
printf("Enter the value of n:\n");
scanf("%d",&n);
i=n;
while(i!=1)
{
if(n==1)
{
a[p]=1;
break;
}
if(n%2==0)
{
a[p]=n%2;
}
else
{
a[p]=n%2;
}
n=n/2;
i=n+2;
i--;
p++;
}
for(j=p;j>=0;j--)
{
printf("%d",a[j]);
}

getch();
}

Is This Answer Correct ?    5 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what are the different data types in c?

749


how to execute a program using if else condition and the output should enter number and the number is odd only...

1651


please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code

1701


What do you mean by a sequential access file?

621


How do I get a null pointer in my programs?

614






Can we declare variable anywhere in c?

533


Is c call by value?

599


When is a null pointer used?

633


What are 'near' and 'far' pointers?

616


Write a program to maintain student’s record. Record should not be available to any unauthorized user. There are three (3) categories of users. Each user has its own type. It depends upon user’s type that which kind of operations user can perform. Their types and options are mentioned below: 1. Admin (Search Record [by Reg. No or Name], View All Records, Insert New Record, Modify Existing Record) 2. Super Admin (Search Record [by Reg. No or Name], View All Records, Insert New Record, Modify Existing Record, Delete Single Record) 3. Guest (Search Record [by Reg. No or Name], View All Records) When first time program runs, it asks to create accounts. Each user type has only 1 account (which means that there can be maximum 3 accounts). In account creation, following options are required: Login Name: <6-10 alphabets long, should be unique> Password: <6-10 alphabets long, should not display characters when user type> Confirm Password: Account Type: Login Name, Password and Account Type should be stored in a separate file in encrypted form. (Encryption means that actual information should be changed and Decryption means that Encrypted information is changed back to the actual information) If any of the above mentioned requirement(s) does not meet then point out mistake and ask user to specify information again. When Program is launched with already created accounts, it will ask for user name and password to authenticate. On successful authentication, give options according to the user’s type.

1509


What is the time and space complexities of merge sort and when is it preferred over quick sort?

671


Why c is called free form language?

566


Can the curly brackets { } be used to enclose a single line of code?

709


cin.ignore(80, _ _);This statement a) ignores all input b) ignores the first 80 characters in the input c) ignores all input till end-of-line d) iteration

630


cavium networks written test pattern ..

3590