Toggle navigation
Courses
Questions
Tags
Users
AC 20161027 期中考 4
0
like
0
dislike
552
views
請設計一個程式,由使用者輸入一個二進位的數,程式會將他轉成十進位後輸出。
sample input:
10101010
sample output
170
[Exercise]
Coding (C)
-
asked
Oct 27, 2016
in
2016-1 程式設計(一)AC
by
Shun-Po
(
18k
points)
ID: 15399 -
Available when:
2016-10-27 18:30:00
-
Due to:
2016-10-27 21:00:00
reshown
Oct 27, 2016
by
Shun-Po
|
552
views
comment
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;
}
Please
log in
or
register
to add a comment.
7
Answers
0
like
0
dislike
Hidden content!#include <stdio.h>
main()\
{
* * * * * * ** a[99], b[99], i, j=0, k;
* * ** * *** ** * * **** h;