Number of hexadecimal values: char * sum (int n, char * num1, char * num2)

Source: Internet
Author: User

Number of hexadecimal values: char * sum (int n, char * num1, char * num2)

Function:

The first parameter n represents the number of hexadecimal values. The maximum value is 36, from 0 to 9, and then A to Z represents 10 to 35.

Char * num1 and char * num2 accept two numeric strings respectively, and then return the result after adding them.

# include using namespace STD; // n indicates the number of hexadecimal digits // A indicates the number of operands 1 // B indicates the number of operands 2 // JY indicates the number of incoming digits // whether jy1 carries char sum1 (INT N, char, char B, int JY, int * jy1) {int num1 = 0; int num2 = 0; If (isdigit (A) num1 = A-'0 '; else num1 = A-'A' + 10; If (isdigit (B) num2 = B-'0'; else num2 = B-'A' + 10; if (num1 + num2 + JY> N) {int temp = num1 + num2 + JY-N; * jy1 = 1; if (temp <10) {return '0' + temp;} else {return 'A' + temp-10;} else {int temp = num1 + num2 + JY; * jy1 = 0; If (temp <10) {return '0' + temp;} else {return 'A' + temp-10 ;}}} char * sum (int n, char * num1, char * num2) {int num1_len = strlen (num1); int num2_len = strlen (num2); int max = num1_len> num2_len? Num1_len: num2_len; int JY = 0; char * He = new char [Max + 2]; memset (HE, 0, Max + 2); For (INT I = 0; I = 0) {A = num1 [num1_len-1-i];} else {A = '0';} If (num2_len-1-i> = 0) {B = num2 [num2_len-1-i];} else {B = '0 ';} he [I] = sum1 (n, a, B, JY, & JY);} return he;} int main () {char * num1 = new char [100]; char * num2 = new char [100]; int N; while (CIN> num1> num2> N) {char * P = sum (n, num1, num2 ); for (INT I = 0; I

Number of hexadecimal values: char * sum (int n, char * num1, char * num2)

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.