nobody is interesting in...
--- In [email protected], "ruhatadiyaman" <ruhatadiya...@...> wrote: > > i am doing Deitel's exercises from Chapter 3(structured program development > in c). i can't write the code which will convert a binary number to decimal. > but before it there was another exercise which wants the code of finding the > palindrome( from book: a palindrome is a number or a text phrase that reads > the same backwards as forwards.ex:12321, 34643...write a program that reads > in a five digit integer and determines whether or not it is a palindrome.) > i wrote this code for this question; > /*palindrome*/ > #include<stdio.h> > > int main() > { > int sayi, a, b, c, d, e, sayi2, end; > printf("sayi gir : "); > scanf("%d", &sayi); > /*seperate the number into digits*/ > a=sayi/10000; > b=(sayi%10000)/1000; > c=(sayi%(10000*a+1000*b))/100; > d=(sayi%(10000*a+1000*b+100*c))/10; > e=(sayi%(10000*a+1000*b+100*c+10*d)); > > > /*calculate the backward of number*/ > printf("%d %d %d %d %d\n", a, b, c, d, e); > sayi2=e*10000+d*1000+c*100+b*10+a; > printf("the backwards of number=%d\n", sayi2); > if(sayi==sayi2) > printf("this is a palindrome\n"); > > > > scanf("%d", &end); > } > > > > so i have wanted to solve 'binary to decimal' on same logic. > > /*BINARY TO DECIMAL*/ > #include<stdio.h> > > int main() > { > int sayi, a, b, c, end; > > while(a!=-1) > { > printf("a binary number= "); > scanf("%d", &sayi); > /*find the number of digits*/ > c=0; > b=10; > while(a!=sayi) > { > a=sayi%b; > b=b*10; > ++c; > printf("%d\n", c); > > > } > printf("the number have %d digits \n", c); > > > } > scanf("%d", &end); > > } > > that's all :( i can not go on to how i will convert it to decimal after i > find the number of digits... > > that's my question. > best regards >
