0 like 0 dislike
2k views
請設計一個程式,由使用者輸入一個二進位的數,程式會將他轉成十進位後輸出。

sample input:

10101010

sample output

170
[Exercise] Coding (C) - asked in 2016-1 程式設計(一)AC by (18k points)
ID: 15399 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00

reshown by | 2k views
0 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()

{
    char a[100];
    int n,c,i;
    scanf("%s",a);
    i=1;
    c=0;
    for(n=strlen(a)-1;n>=0;n--)
    {
        c=c+i*(a[n]-'0');
        i=i*2;
    }
    printf("%d",c);
    return 0;
}

7 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>

main()\

{
* ** **** * ** * a[99], b[99], i, j=0, k;
***** *** * ** * * ** h;
* ** * * * ** *** * * ** &i);
* * * **** * **** * ***

   (
* ** ** ** *** * * ** **** * * a[i];
* * **** * * ***** ** ** * *** *** *** * * * * *

   )
* * * * * ***** *** *

   (
** * * **** * * * * * * * ****** **** b[i];
* * * ** * * ** * * * * * ** ** * *
* ** ********** * ** * * ** * * * * * ** * *
*** * ** ** * ** ***** *
***** ** * * ** *** * ** * *** * ** * ***** * * * *
* * *** * ** * * * * **** **** **** ** *** *****
* ** * * **** ** * ***** * ** * ** * * **** = b[j];
* ** * ** ** ** *** *** ** *** * * ** * * = a[k];
** * * * * *********** ** ** * ** ******* * * * * * ** = temp;
**** * *** ** * ** *** **** * * * ** * ** **
** * * ** ** * * * ** * * *

   )



   if (i/2!=0)
*** ** **** ** *** ** *** * (b[i/2] + b[(i/25)+1)/2
** *** ****
* *** *** * *** * ****** = b[i/2];
* ** ** **** ** * ** * * * ** * * b[j])
* ** * * * 0;

}
answered by (-52 points)
0 like 0 dislike
Hidden content!
*** *** **** * *****
* *** * * ** ** * *



int **

{
** **** * * *** * *** **


* * * ***** * * * * * * ***** * **** ** **** * * *** *** * * ** ** **


* ****** ** ** = 128 * a + 64 * b + 32 * c + 16 * d + 8 * e + 4 * f + 2 * g + h;


** * ** * ** * * * *** *** ** **


*** * * ** **** 0;

}
answered by (180 points)
0 like 0 dislike
Hidden content!
*** * ** ** ***
* * ** * * **** *



int * *

{
* *** *** * ** ** ** ** *


* * * * ** **** **** * **** ** * * * *** ** ** * ***** * * ** *** ** **** * * ** * * **


* * * * ** **** = 128 * a + 64 * b + 32 * c + 16 * d + 8 * e + 4 * f + 2 * g + h;


* * *** * * * ** *** ** ** * * * ***


** * ** ** ** ** *** * 0;

}
answered by (180 points)
0 like 0 dislike
Hidden content!
#include ** **

#include * ** *****



int main( int argc, char )

{
** * ** * **** *** ** *** iNum;
* ** * ** ** * * ************ * * ** * * * ** *** * *
*** * * **** ** **** ** * ** * ***** *
** ** ** **** * ** * ** * * * ** * ** %d\n", iNum, iNum);


* ***** ** * * ** * * ****** ** ****
* ** *** * * * ** * ***** 0;

}
answered by (-74 points)
0 like 0 dislike
Hidden content!
#include * *** **

#include * *****

#include ** * ***** *
* * * ** * ** * *

int()

{
*** * * **** * * * * **** x;
* *** * *** temp = 0;
* * * * *** *** * * * * ** * x;
* * * * ** *** * (x > 0)
** ** * * **
* * * * * ** * = 2 * temp +%10;
****** ****** ***
* ****** ** *** ***
* *** **** **** ** *** ** ** temp *** ** * endl;


** **** **** * *** * 0;



}
answered by (-74 points)
0 like 0 dislike
Hidden content!
** * **** * ** * *
******* **

int main()

{
** *** **** * * *


* ** * * *** * * *** *



if(n%10!=0)
** ** ***** * * ***** *

a=(n%10)*1;

}



else if(n%100!=0)

{
* * **** * * ** **

}

else if(n%1000!=0)

{
* ** *** * * * * **

}

else * ** * *

{
* * ** ** * * * **** *** *

}

else

{
* * ****** **** * ** * * * **

}

else **** * **

{
*** * * *** **** * * * ** **** *** * * * * *

}

else ** *** **

{
* * ** * ** ******* * *** *** * * * ** *

}

else * **** * * **

{
***** ** *** * ** * ** * * * * * * * ****** ** ***

}
* * * * * ***
* ******* ** *** **

return 0;

}
answered by (-248 points)
0 like 0 dislike
Hidden content!
#include<stdio.h>





int main(){
* ** * ** * * **** * * x,y=0,i,j=0,n=1;
* * * ** ** * ** *** ** ** **** *

    do{
**** * *** * **** ***** * * ** ** ***** **** * *
**** *** **** * **** ** * *** * ******* * * * ** *
* * * ** ** **** * * *** ** * ** *** *** * *
****** * * * * * * * ******** ***** ** * *** ******


* * ** * * *** * *** * * ***
* **** * ** ** ** ** * * **** * *
** ** * * ** * *** * * **** * 0;

}
answered by (-126 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:104.23.197.94
©2016-2026

Related questions

0 like 0 dislike
0 answers
[Resource] asked Oct 27, 2016 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 15475 - Available when: Unlimited - Due to: Unlimited
| 13 views
0 like 0 dislike
5 answers
[Exercise] Coding (C) - asked Oct 27, 2016 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 15447 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00
| 1.8k views
1 like 0 dislike
37 answers
[Exercise] Coding (C) - asked Oct 27, 2016 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 15446 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00
| 6.4k views
1 like 0 dislike
17 answers
[Exercise] Coding (C) - asked Oct 27, 2016 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 15442 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00
| 3.1k views
1 like 0 dislike
18 answers
[Exercise] Coding (C) - asked Oct 27, 2016 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 15440 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00
| 3.2k views
12,783 questions
183,442 answers
172,219 comments
4,824 users