tomhanks,
I did some modifications and here is the code WORKING
#include <stdio.h>
int Bin2Dec(int* ,int );
int power (int , int );
void main (void)
{
int x, dec;
int binary_num[100];
int digits;
printf("Please enter the number of digits of the binary number:");
scanf ("%d",&digits);
printf("Please enter the LSB of the binary number:");
for(x=0;x<digits;x++)
{
scanf ("%d",&binary_num[x]);
if ((binary_num[x]!=0) && (binary_num[x]!=1))
{
printf("ERROR..the binary number consists of 0's and 1's only");
return;
}
if (x<digits-1) printf("Please enter the next digit of the binary number:");
}
dec=Bin2Dec(binary_num,digits);
printf("The corresponding decimal number is %d \n", dec);
}
int Bin2Dec(int* binar,int digits)
{
int broj = 0,i;
for(i=0;i<digits+1;i++)
{
if(binar == 1) broj += power(2,i);
}
return (broj);
}
int power (int x, int y)
{
int k,z=1;
for (k=1;k<y+1;k++)
{
z=z*x;
}
return(z);
}
PS: enter the binary number digit by digit from right to left (from LSB to MSB)