二进制转换为十进制 C语言高手进

二进制转换为十进制 C语言高手进
二进制转换为十进制

Time Limit:1000MS Memory Limit:65536K
Total Submit:163 Accepted:60

Description

输入一个二进制数(仅由0和1构成的整数),打印出该数对应的十进制数。

Input

第一行是测试数据的组数n,下面的n行是每一行是一个二进制数。

Output

输出为n行,分别为对应输入的十进制数。

Sample Input

2
11
110

Sample Output

3
6

Source

怎么做???
好的追分!!!!
第一个连编译都通不过啊。。。
请经过测试后在回答!!!!
/*看厅圆看吧*/

#include
#include
#include
#include

#define MAX_LEN 40
#define MAX_COUNT 20

void main()
{
int count = 0;
char array[MAX_COUNT][MAX_LEN];

printf("请输入个数及二进制数: \n");
scanf("%d", &count);

getchar();
for(int i=0; i gets((char*)&array[i]);

printf("对应的十进制数是模伏竖: \n");
for(i=0; i {
int iDec = 0;
int len = strlen(array[i]);
int index = 0;
while(len--)
{
iDec += pow(2, index) * (atoi(array[i]) & 1);
array[i][len] = '\0';
index++;
}

printf("%d\n"旦大, iDec);
}
}
Omaha
← 上一篇: 下一篇: →