0
Help me to rectify the problem for binary to decimal conversion program its only giving output when all the digits are same( 1).
4 Respostas
0
you wrote if a[num] ==1 it's if a[j] ==1, and I think that you should the max index should be num-1.
0
Thanks but it is not working like u have said..
0
#include <stdio.h>
#include<math.h>
int main()
{
int a[100], num, i, j, sum = 0;
scanf("%d", &num);
for (i = 0; i <= num - 1; i++)
{
scanf("%d", &a[i]);
}
for (j = num - 1; j >= 0; j--)
{
if (a[j] == 1)
{
sum += pow(2,num-1-j);
}
}
printf("%d", sum);
return 0;
}
0
Thanks alot bro ❣️❣️❣️