回覆列表
  • 1 # 使用者1905193500098

    一下兩個程式均在VC在編譯透過。/*如果這個二進位制數比較大的話, 大到只能用陣列儲存這個二進位制數,當然如果大到轉化成10進位制int存不下的情況那另當別論*/#include<stdio.h>#include<string.h>int main(){ char a[33]; int i, num = 0; scanf("%s", a); for(i=strlen(a)-1; i>=0; i--) { num*=2; /*如果用位運算的話,速度會更快*/ num+=a[i]-"0"; } printf("%d\n", num); return 0;}/*如果這個二進位制數的位數不超過10位的話可用這個程式*/#include<stdio.h>int main(){ int num = 0, a, j=1; scanf("%d", &a); while(a) { num += (a%10) * j; a /= 10; j *= 2; } printf("%d\n", num); return 0;}

  • 中秋節和大豐收的關聯?
  • 如何評價李雪健的演技?