You are on page 1of 3

ASSIGNMENT 2

---------------------------------------------------------------------------
Q. Implement large number arithmetic with a singly linked list. Use
polynomial operations.
Polynomial arithmetic can be used in a real-life situation such as large
number addition or multiplication.
The given input numbers are decomposed into two computers readable
polynomials with the radix of 10000.
For example: if the given number is 12345678, then it is stored as the
polynomial: 1234 x^1 + 5678x^0.
Similarly, the other input number is also taken in the form of the
decomposed polynomial and the addition or multiplication is done.
The final answer is also printed in the form of a polynomial.
The functions for creating a linked list, adding two linked lists and
multiplication of two linked lists is taken from the previous assignment.
The important logic of the code is “decomposing the large input number
into the coefficient of the polynomial”.
Algorithm:
X and y are the input numbers.
I and j are the degree terms
H and k are used to pass the coeffcients to the insert function

While number 1 is not equals to 0 do


{
H =x%10000; it decomposes it in the 4 digit coefficent

x=x/10000;

insert(&head1,h,i); it calls the insert function and the 4 digit term


. gets inserted as coefficient

i++; I is initially taken 0 and it is used to pass the degree of the . .


. term
}

It is also same for the second input number:

While number 2 is not equals to 0 do


{
k=y%10000;
y=y/10000;
insert(&head2,k,j);
j++;
}

You might also like