+ 1

# Binary to decimal horners method

I want to write program in C which converts binary number to decimal. I have the function Int convert(int *T, int n) { w=T[] ; For(int i=0;i<n;i++) w=w*2+T[i] Return w; } But i dont know if its ok or not, can someone explain please? I dont know how to use it

21st Apr 2021, 3:52 PM
Klaudiusz Biegacz
+ 2
Well it is really helpful and it works thank you for that, but still with pow method it wont be done with the horners one. I need it to use the horners scheme.
25th Apr 2021, 9:20 AM
Klaudiusz Biegacz
+ 1
I am assuming the integer array T contains the digits of the binary number as elements and n is the size of the array. Then you would need to use the special math header file and use the pow() function for calculating the return value, w. The following are the hints: - use '#include <math.h>' - Initialize the return value, w to 0. - in the for loop, use 'w=w+pow(2,i);' The convert function should be called in the main function of C for it to be executed. Request you to also check the syntax in C Please tell me if you need the full code as well
24th Apr 2021, 5:53 PM