Thanks for the effort !!!
"lonely_khuui" <[email protected]> Thu, 22 Feb 2007 03:23:55 -0000
| Newsgroups | gmane.comp.programming.cppug |
|---|---|
| Message-ID | <[email protected]> |
Hi Anuj;
Thanks alot for your marvellous idea,it was great !!
I couldn't imagine that i would solve it,but of course with your help
i did it.
I really appreciate.......Infact while trying to solve it i got
another idea which was quite interesting
...ideas produce ideas...I learnt alot in this experiment.Once again
thanks alot.
This is your idea
// Decimal-Binary convertion
#include<iostream.h>
int main()
{
while(1){
int memory[100]; // Array of holding data
int number;
int copy_number; // A copy of the integer (for another task)
int remainder;
cout<<"Enter an Integer :";
cin>>number;
copy_number=number;
cout<<number<<" when converted to binary,it becomes:";
for(int i=0;copy_number>0;i++){ // 1st task (knowing the number of
bits)
copy_number/=2;
}
i--;
int index=i;
while(number>0){ // 2nd task (calculation)
remainder=number%2;
memory[index]=remainder;
number/=2;
index--;
}
index++;
for(index;index<=i;index++){
cout<<memory[index];
}
cout<<endl;
}
return 0;
}
It worked tremendously.
Based on that i thought another way.....
// Decimal-Binary Conversion (10 bit ?)
#include<iostream.h>
#include <math.h>
int main()
{
while(1){
long decimal;
long binary=0; // initial sum
cout<<"Enter an Integer :";
cin>>decimal;
cout<<decimal<<",when converted to binary,it becomes :";
for(int i=0;decimal!=0;i++)// indices of the digits
{
long firstDigit=decimal%2;
binary+=firstDigit*long(pow(10,i));// reverses the digits and finds
their place values
decimal /=2;
}
cout<<binary;
cout<<endl<<endl;
}
return 0;
}
but with this,it has some limitations,it only solves a maximum of 10
bit number.I really dont know why.Please help me sort it out.
Kind regards.Hashim
------------------------ Yahoo! Groups Sponsor --------------------~-->
Great things are happening at Yahoo! Groups. See the new email design.
http://us.click.yahoo.com/lOt0.A/hOaOAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups - Join or create groups, clubs, forums & communities. Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/cppug/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/cppug/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[email protected]
mailto:[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups - Join or create groups, clubs, forums & communities. is subject to:
http://docs.yahoo.com/info/terms/