C program to convert a binary number to an equivalent decimal number
kw.c
#include<stdio.h>intmain(){longn;intr,dn=0,i=1;printf("———————————————————————————————————————————");printf("\nProgram to convert a binary number to decimal");printf("\n———————————————————————————————————————————");printf("\nEnter the binary number ");scanf("%ld",&n);while(n!=0){r=n%10;dn=dn+r*i;i=i*2;n=n/10;}printf("\nEquivalent decimal number is %d",dn);printf("\n———————————————————————————————————————————\n");return0;}
Output
kodingwindow@kw:~$ gcc kw.c kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Program to convert a binary number to decimal
———————————————————————————————————————————
Enter the binary number 11111111
Equivalent decimal number is 255
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.