Binary to Decimal

hey, what is the problem with it?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define size 4

int main()
{
	int array[size];
	int i,input,j;
	double	num=0;

	printf("Enter The Binary digit: ");
	scanf("%d",&input);

	for(i=1;i<=size;i++)
	{
		if(input!=0)
		 {
		   array[i]=input%10;
			input=input/10;
		 }
	}
	for(j=0;j<size;j++)
	{
			num=num+(array[j] * pow(2,j));
		
	j++;
    }
	printf("%d",num);
	getch();
	return 0;
}
what is the problem indeed.
I don't see any just by looking at it.
well, maybe except that array is not initialized to 0, so if you enter less than 4 digits, you'll get some rubbish.

though generally, do you realize, that here a string is converted to a decimal number, then you convert that number into an array and then to binary? do you really need to do all that?

also pow isn't necessary here. you could write
for(j = size-1; j >= 0; j--) num = num*2+array[j];
Topic archived. No new replies allowed.