Question:

Published on: 24 June, 2024

**Write a C program to convert binary to decimal using function.**

Answer:

#include<stdio.h> #include<conio.h> #include<math.h> int bin_to_dec(int); main() { int n,result; printf("\n Enter any binary number"); scanf("%d",&n); result=bin_to_dec(n); printf("\n The equivalant decimal=%d",result); getch(); } int bin_to_dec(int x) { int i=0,digit,sum=0; do { digit=x%10; sum=sum+digit*pow(2,i); x=x/10; i++; }while(x!=0); return(sum); }

Output:

Subjects

Trending

**Write a C program to find both the largest and smallest number in list of integers.**

View : 544

24 June, 2024

Random questions