{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

stack_example - ADDITION OF TWO NUMBERS WITH MAX SIZE UP TO...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
ADDITION OF TWO NUMBERS WITH MAX SIZE UP TO 40 DIGITS 289765 and 897 Read the numbers and stack them (upside down) stack1 stack2 s 5 7 s 6 9 s 7 8 s 9 s 8 s 2 Add corresponding elements and take care of carry – 2354 and 897 ?? typedef struct { int *items; int top; const int max;
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
} stack; typedef enum {false, true} bool; bool push(stack *a, int item); int pop(stack *a); void readNumber(stack *location, bool *isnegative); void printNumber(stack *number, bool isnegative); int compareNumbers(const int first[], int first_top, const int scnd[], int scnd_top); void addition(stack *first_number, bool first_negative, stack *scnd_number, bool scnd_negative, stack *answer); void add(stack *first, stack *scnd, stack *answer); int main(void) { bool first_negative, scnd_negative; char choice; stack first_number, scnd_number, answer; int a[82], f[40], s[40]; //These are to be used to allocate the proper //amount of space for each stack first_number.max = scnd_number.max = 40; answer.max = 82; first_number.top = scnd_number.top = answer.top = -1; first_number.items = f; scnd_number.items = s; answer.items = a; addition(&first_number,first_negative, &scnd_number,
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern