A programe to convert binary into decimal using Function.
#include<conio.h> #include<stdio.h> void convert(int ); void main() { int num; printf("Enter a binary number(1s and 0s) \n"); scanf("%d", &num); convert(num); getch(); } void convert(int num ) { int binary_val, decimal_val = 0, base = 1, rem; binary_val = num; while (num > 0) { rem = num % 10; decimal_val = decimal_val + rem * base; num = num / 10 ; base = base * 2; } printf("The Binary number is = %d \n", binary_val); printf("Its decimal equivalent is = %d \n", decimal_val); } Output Enter a binary number(1s and 0s) 100 The Binary number is = 100 Its decimal equivalent is = 4 ...


Comments
Post a Comment