A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to convert number from Decimal to Binary
Q:

C program to convert number from Decimal to Binary

0

C program to convert number from Decimal to Binary

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Decimal to Binary Conversion using C program

/*C program to convert number from decimal to binary*/
 
#include <stdio.h>
 
int main()
{
    int     number,cnt,i;
    int     bin[32];
 
    printf("Enter decimal number: ");
    scanf("%d",&number);
 
    cnt=0;              /*initialize index to zero*/
    while(number>0)
    {
        bin[cnt]=number%2;
        number=number/2;
        cnt++;
    }
 
    /*print value in reverse order*/
    printf("Binary value is: ");
    for(i=(cnt-1); i>=0;i--)
        printf("%d",bin[i]);
 
    return 0;
}

Output:

Enter decimal number: 545
Binary value is: 1000100001

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now