當前位置:編程學習大全網 - 編程軟體 - 時尚節目

時尚節目

# include & ltstdio.h & gt

# include & ltstring.h & gt

int poll(int a,int b)

{

int i,s = 1;

for(I = 1;我& lt= b;i++)

s = s * a;

返回s;

}//用戶定義的冪函數

int main()

{

int i,j,k,l,n,m;

int t;

char a[100];

int poll(int a,int b);

while(scanf("%d %s ",& ampn,a)!=EOF)//輸入

{

t = 0;

l = strlen(a)-1;

printf("%d\n%s\n ",n,a);//輸入和輸出

for(I = 0;壹個[我]!='\0';I++)//轉換過程

{

如果(n!=16)

{

t=t+(a[i]-'0')*poll(n,l);

l-;

}

其他

{

if(a[I]& gt;= ' A ' & amp& ampa[I]& lt;='f ')

t=t+(a[i]-'A'+10)*poll(n,l);

其他

t=t+(a[i]-'0')*poll(n,l);

l-;

}

}

printf("%d\n ",t);//期望的結果

}

}

這段代碼沒有錯。如果妳不明白,再問我。

其中n為2或8或16,或其他數,a[]為n對應的二進制數。

以下是輸入和輸出的示例

2 10101010110

2

10101010110

1366

8 777777777

777777777

134217727

16 F08F89FAD

16

F08F89FAD

150511533

  • 上一篇:用java編程計算1^1+2^2+3^3+4^4+5^5+……+20^20,不用實型數,用數組進行計算
  • 下一篇:V型工作站使用什麽操作系統?
  • copyright 2024編程學習大全網