Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The largest number data type that is available in C is the long long which represents a 64-bit number. Using an unsigned long long, you

The largest number data type that is available in C is the long long which represents a 64-bit number. Using an unsigned long long, you can represent numbers up to around 110^20 (a 20 digit number). Some times, however, you want to deal with numbers larger than this limit. In this case, you have to develop custom routines to manipulate these numbers.

One way that this can be done is to read these numbers in as strings, and manipulate them digit by digit using the algorithms that you were taught in primary school to perform addition, subtraction etc on paper.

For this assignment, you need to write a C program that accepts two numbers as strings and outputs the sum of these two numbers to the screen. Each of the numbers may be up to 100 digits long.

As an extended goal, one or both of these numbers may be signed and you need to handle these cases as well. Only 20% of test cases will require the handling of signed numbers. This greatly increases the complexity of the algorithm and you need to consider if the extra time penalty justifies the extra marks.

You may not use any external libraries to assist you with this question (i.e. it must compile and run within the Moodle environment).

Example input (without signs):

100000000000000000000

200000000000000000000

Example output:

300000000000000000000

In this case, the output "300000000000000000000" is just the sum of the two input numbers "100000000000000000000" and "200000000000000000000".

Example input (with signs):

300000000000000000000

-100000000000000000000

Example output:

200000000000000000000

In this case, the sum of "300000000000000000000" and "-100000000000000000000" is "200000000000000000000"

Requested files

main.c

1 #include

2

3 int main(void)

4 {

5 return 0;

6 }

The largest number data type that is available in C is the long long which represents a 64-bit number. Using an unsigned long long, you can represent numbers up to around 110^20 (a 20 digit number). Some times, however, you want to deal with numbers larger than this limit. In this case, you have to develop custom routines to manipulate these numbers.

One way that this can be done is to read these numbers in as strings, and manipulate them digit by digit using the algorithms that you were taught in primary school to perform addition, subtraction etc on paper.

For this assignment, you need to write a C program that accepts two numbers as strings and outputs the sum of these two numbers to the screen. Each of the numbers may be up to 100 digits long.

As an extended goal, one or both of these numbers may be signed and you need to handle these cases as well. Only 20% of test cases will require the handling of signed numbers. This greatly increases the complexity of the algorithm and you need to consider if the extra time penalty justifies the extra marks.

You may not use any external libraries to assist you with this question (i.e. it must compile and run within the Moodle environment).

Example input (without signs):

100000000000000000000

200000000000000000000

Example output:

300000000000000000000

In this case, the output "300000000000000000000" is just the sum of the two input numbers "100000000000000000000" and "200000000000000000000".

Example input (with signs):

300000000000000000000

-100000000000000000000

Example output:

200000000000000000000

In this case, the sum of "300000000000000000000" and "-100000000000000000000" is "200000000000000000000"

Requested files

main.c

1 #include

2

3 int main(void)

4 {

5 return 0;

6 }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Combinatorial Testing In Cloud Computing

Authors: Wei-Tek Tsai ,Guanqiu Qi

1st Edition

9811044805, 978-9811044809

More Books

Students also viewed these Programming questions