943,752 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 307
  • C++ RSS
Nov 13th, 2008
0

plz help me

Expand Post »
hi.

i have to do addition,multiplication,division and substraction of large numbers using c++.

Using pointers and struct .I m sending some code.plz if anyone can do this program help me.

here r some code
plz send me on fri_003@yahoo.co.in
as soon as possible.

C++ Syntax (Toggle Plain Text)
  1. #include<stdio.h>
  2.  
  3. struct node
  4. {
  5. long int data;
  6. struct node* llink;
  7. struct node* rlink;
  8.  
  9. node()
  10. {
  11. data=0;
  12. llink = NULL;
  13. rlink = NULL;
  14. }
  15.  
  16. };
  17.  
  18.  
  19. struct head
  20. {
  21.  
  22. int noofdigit;
  23. char sign;
  24. struct node* left;
  25. struct node* right;
  26.  
  27.  
  28. head()
  29. {
  30. noofdigit = 0;
  31. sign =0;
  32. left = NULL;
  33. right =NULL;
  34. }
  35.  
  36. };
  37.  
  38. char Sign(struct head* headpointer)
  39. {
  40. return headpointer->sign;
  41. }
  42.  
  43.  
  44.  
  45. struct node* FirstLeft(struct head* headpointer)
  46. {
  47. return headpointer ->left;
  48. }
  49.  
  50. struct node* FirstRight(struct head* headpointer)
  51. {
  52. return headpointer ->right;
  53. }
  54.  
  55.  
  56. struct node* NextLeft(struct node* nodetosearch)
  57. {
  58. return nodetosearch ->rlink;
  59. }
  60.  
  61. void InsertLeft(struct head* headnode,struct node* nodetoinsert)
  62. {
  63.  
  64. if(FirstLeft(headnode) ==NULL || FirstRight(headnode) == NULL)
  65. {
  66. headnode ->left = nodetoinsert;
  67. headnode ->right = nodetoinsert;
  68. }
  69.  
  70. else
  71.  
  72. {
  73. headnode ->left->llink = nodetoinsert;
  74. nodetoinsert->rlink = FirstLeft(headnode);
  75. headnode->left = nodetoinsert;
  76. }
  77. }
  78.  
  79.  
  80. int over_flow(struct node* nodetochk)
  81. {
  82. long int ovrflwdgt = 0;
  83.  
  84. ovrflwdgt = nodetochk->data / 100000000;
  85. if(ovrflwdgt !=0)
  86. {
  87.  
  88. nodetochk->data = nodetochk->data - (ovrflwdgt* 100000000);
  89. }
  90. return ovrflwdgt;
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97. void Add(struct head* oprnd1,struct head* oprnd2,struct head* result)
  98. {
  99.  
  100.  
  101. struct node* n1,*n2 , *rslt;
  102. long int sum,ovrflwdgt = 0;
  103.  
  104. if(Sign(oprnd1) == Sign(oprnd2))
  105. {
  106.  
  107. n1 = FirstRight(oprnd1);
  108. n2 = FirstRight(oprnd2);
  109.  
  110. while(n1!=NULL && n2!=NULL)
  111. {
  112.  
  113. sum = n1->data + n2->data + ovrflwdgt;
  114. rslt = new struct node;
  115. rslt->data = sum;
  116. InsertLeft(result,rslt);
  117. ovrflwdgt = over_flow(rslt);
  118. n1 = NextLeft(n1);
  119. n2 = NextLeft(n2);
  120. }
  121.  
  122. while(n1 != NULL)
  123. {
  124.  
  125. sum = n1->data + ovrflwdgt;
  126. rslt = new struct node;
  127. rslt->data = sum;
  128. InsertLeft(result,rslt);
  129. ovrflwdgt = over_flow(rslt);
  130. n1 = NextLeft(n1);
  131. n2 = NextLeft(n2);
  132. }
  133.  
  134. while(n2 != NULL)
  135. {
  136. sum = n2->data + ovrflwdgt;
  137. rslt = new struct node;
  138. rslt ->data = sum;
  139. InsertLeft(result,rslt);
  140. ovrflwdgt = over_flow(rslt);
  141. n2 = NextLeft(n2);
  142. }
  143.  
  144. if(ovrflwdgt > 0)
  145. {
  146.  
  147. rslt = new struct node;
  148. rslt->data = ovrflwdgt;
  149. InsertLeft(result,rslt);
  150. }
  151.  
  152. }
  153.  
  154. }
Last edited by cscgal; Nov 13th, 2008 at 4:25 pm. Reason: Added code tags
Similar Threads
Reputation Points: 7
Solved Threads: 0
Newbie Poster
laki234 is offline Offline
10 posts
since Nov 2008
Nov 13th, 2008
0

Re: plz help me

No one here is likely to "do it for you". If you have a question, we'll be glad to answer.

Please read the sticky posts at the top of this forum, and place code tags around your program code, like:
[code]
your code goes here
[/code]
Reputation Points: 1268
Solved Threads: 228
Posting Virtuoso
vmanes is offline Offline
1,895 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Problem adding in stack
Next Thread in C++ Forum Timeline: c++ STL LIST function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC