#include <stdio.h>
#include <string.h>
int zh( char str[])
{
int sum = 0;/*定义总值*/
int j = 1;/*交换数值*/
int pot = strlen(str) - 1;/*把str数组值先减一*/
for (; pot >= 0; pot--) /*循环 pot值 每次减一*/
{
sum += (str[pot] - '0')*j;
j*=2;/*每次j都乘2*/
}
return sum;
}
int main()
{
int result;
char a[10];
scanf_s("%s",a,10);
result = zh(a);
printf("thit is number %d\n",result);
return 0;
}
是二进制转10进制
#include <stdio.h>
#include <string.h>
int zh(char str[])
{
int sum = 0;/*定义总值*/
int j = 1;/*交换数值*/
int pot = strlen(str) - 1;/*把str数组值先减一*/
for (; pot >= 0; pot--) /*循环 pot值 每次减一*/
{
sum += (str[pot] - '0')*j;
j*=2;/*每次j都乘2*/
}
return sum;
}
int main()
{
int result;
char a;
printf("please input 1001 number ");
scanf_s("%d",a);
result= zh(a);
printf("thit is number %d\n",result);
return 0;
}
#include <stdio.h>
#include <string.h>
int zh(char str[])
{
int sum = 0;/*定义总值*/
int j = 1;/*交换数值*/
int pot = strlen(str)-1;/*把str数组值先减一*/
for (; pot >= 0; pot--) /*循环 pot值 每次减一*/
{
sum += (str[pot] - '0')*j;
j*=2;/*每次j都乘2*/
}
return sum;
}
int main()
{
int result;
char a[1001]={0};
printf("please input 1001 number ");
scanf("%s",a);
result= zh(a);
printf("thit is number %d\n",result);
return 0;
}
估计意思差不多是这样。求的是各个位数乘 j 再相加的和