Please support our C advertiser: Programming Forums
Views: 1331 | Replies: 4
![]() |
I wish you had written the language which you are using...
I wrote it in C but you can easily integrate it on C++...
I wrote it in C but you can easily integrate it on C++...
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <math.h> int main() { char ch;//input character int ascii;//input's ascii equivalent int b,i; double sum = 0;//You can initilaize it to int but some compilers(like Dev-C++) causes troubles and generates wrong output... printf("Enter any character "); scanf(" %c",&ch); ascii = ch;//if you asssign a char to an int, the int variable holds the assigned character's ASCII code for(i = 0;; i++) { b = ascii % 2;//converting binary... ascii /= 2;//converting binary... sum += b * pow(10,i);//variable b's first value is first digit the binary code from right to left //so we multiply it by E+0 printf("%0.lf\n",sum);//Watch how your variable to be converted in ASCII if(ascii == 1 || ascii == 0) break;//If we divide an integer to 2, we obtain 1 or 0 as a result //if we don't control this will be an infinite loop. } sum += ascii * pow(10,i + 1);//End of our loop we divided the value 2 again and the variable ascii's value was 1 //so we exit the loop beacause of the if statement and we didn't multiply it E + 6.We are doing this here. printf("%0.lf",sum);//Output... return 0; }
Last edited by FoX_ : Mar 21st, 2007 at 10:32 am.
Well, you must post whatever you have tried till now. See this
But since, you have got solution, you may see this too:
http://www.daniweb.com/code/snippet656.html
But since, you have got solution, you may see this too:
http://www.daniweb.com/code/snippet656.html
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode