2-16 decimal conversion (implemented by C language algorithm)

Source: Internet
Author: User

Today, I insisted on writing algorithms on the fifth day. Since I have never learned the c language, and I used mircrosoft c ++ 6.0, it was too difficult to use and so sad. After some column tests, the number system is finally converted. Still have a certain sense of accomplishment, hey.

Let's talk less about the code.

# Include "stdio. h"
# Include "math. h"
Void main (){
Int q, m, k, p, s [50];
Double n;
M = 0;
Printf ("\ n please input the decimal number n :");
Scanf ("% lf", & n); // enter % lf
Printf ("\ n please input the number of converted hexadecimal numbers p (2-16 ):");
Scanf ("% d", & p );
Printf ("(% f) 10 = (", n );
While (n! = 0 ){
Q = fmod (n, p );
N = floor (n/p );
M ++;
S [m] = q;
}
For (k = m; k> = 1; k --){
If (s [k]> 9 ){
Printf ("% c", s [k] + 55 );
}
Else {
Printf ("% d", s [k]);
}


}
Printf (") % d \ n", p); // The position must be placed after the for loop. Otherwise, the result is not output in one piece.
}

I want to learn the data structure today. I can use the stack to complete it. I will try it later.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.