plz help me

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 10
Reputation: laki234 is an unknown quantity at this point 
Solved Threads: 0
laki234 laki234 is offline Offline
Newbie Poster

plz help me

 
0
  #1
Nov 13th, 2008
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.

  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,678
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: plz help me

 
0
  #2
Nov 13th, 2008
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]
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC