Advertisement
HelloDearSir

Untitled

Mar 9th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. #include <conio.h>
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. #define P 31
  8. #define z 20
  9.  
  10. void prints(void);
  11. int m[z];
  12. int s[z];
  13. int i,j ;
  14. void printa(void);
  15. void printb(void);
  16. void sqaurea(void);
  17. void modb(void);
  18. void subractb(void);
  19. int a[10], b[20];
  20. void carryb(void);
  21. void main(void)
  22. {
  23. //prints();
  24. //s[2] = 1;
  25. //prints();
  26.  
  27. // clear a[] b[]
  28. //for (int i = 0; i < 10; i++) a[i] = 0;
  29. //for (int i = 0; i < 20; i++) b[i] = 0;
  30. //printa();
  31. //printb();
  32. //set a[] to number square
  33. for (int k = 0; k < P - 2; k++)
  34. {
  35.  
  36. cout << "P = " << P << " iteration = " << k + i << endl;
  37.  
  38.  
  39. //squareing a and storing this into b
  40.  
  41. cout << "Squaring :";
  42. sqaurea();
  43. printb();
  44.  
  45. //pefroming the carry
  46. cout << "Carry : ";
  47. carryb();
  48. printb();
  49.  
  50.  
  51. //takuing 2 away from b
  52.  
  53. cout << " sub 2: ";
  54. subractb();
  55. printb();
  56.  
  57. // printing the mod from b and placing it into a
  58. cout << "mod = ";
  59. carryb();
  60. printa();
  61.  
  62. // clear b
  63.  
  64. for (int i = 0; i < z; i++) b[i] = 0;
  65.  
  66. cout << endl;
  67. }
  68.  
  69. //square the number
  70.  
  71.  
  72. printa();
  73.  
  74.  
  75.  
  76. carryb();
  77.  
  78.  
  79.  
  80.  
  81.  
  82. _getch();
  83.  
  84. }
  85.  
  86. void prints(void)
  87. {
  88. //co//ut << "S=";
  89. //for (int i = z - 1; i >= 0; i--)
  90. // {
  91.  
  92. // cout << s[i];
  93.  
  94. //}
  95. //cout << "\n";
  96. }
  97.  
  98. void printa(void)
  99. {
  100. cout << "a[]=";
  101. for (int i = 9; i > -1; i--) cout << a[i];
  102. cout << endl;
  103. }
  104.  
  105.  
  106. void carryb(void)
  107. {
  108. for (int i = 0; i < z; i++) {
  109.  
  110. if (b[i] > 16383) { b[i] -= 16384; b[i + 14]++; }
  111. if (b[i] > 8191) { b[i] -= 8192; b[i + 13]++; }
  112. if (b[i] > 4095) { b[i] -= 4096; b[i + 12]++; }
  113. if (b[i] > 2047) { b[i] -= 2048; b[i + 11]++; }
  114. if (b[i] > 1023) { b[i] -= 1024; b[i + 10]++; }
  115. if (b[i] > 511) { b[i] -= 512; b[i + 9]++; }
  116. if (b[i] > 255) { b[i] -= 256; b[i + 8]++; }
  117. if (b[i] > 127) { b[i] -= 128; b[i + 7]++; }
  118. if (b[i] > 63) { b[i] -= 64; b[i + 6]++; }
  119. if (b[i] > 31) { b[i] -= 32; b[i + 5]++; }
  120. if (b[i] > 15) { b[i] -= 16; b[i + 4]++; }
  121. if (b[i] > 7) { b[i] -= 8; b[i + 3]++; }
  122.  
  123. if (b[i] > 3) { b[i] -= 4; b[i + 2]++; }
  124. if (b[i] > 1) { b[i] -= 2; b[i + 1]++; }
  125. }
  126. }
  127.  
  128. void modb(void)
  129. {
  130. int count = 0;
  131.  
  132. //clearing b
  133. for (int i = 0; i < z; i++) b[i] = 0;
  134.  
  135. do {
  136. for (int i = 0; i < P; i++)
  137. {
  138. b[i] += b[i + count];
  139. if (b[i] > 1)
  140. {
  141. b[i] -= 2;
  142. b[i + 1] ++;
  143. }
  144. }
  145. count += P;
  146. } while (cout << z);
  147. //clearing x
  148. for (int i = 0; i < z; i++) b[i] = 0;
  149. }
  150.  
  151.  
  152. void subractb(void)
  153. {
  154. int index;
  155. if (b[1] == 1)
  156. {
  157. //cheack if the 2 units are 1. If they are chage it to zero
  158. b[1] == 0;
  159. }
  160. else {
  161. for (int i = 2; i < z; i++)
  162. {
  163. if (b[i] == 1)
  164. {
  165. index = i;
  166. (index) = 0;
  167. i = z;
  168. }
  169. }
  170. for (int i = index - 1; i > 0; i--)
  171. {
  172. b[i] = 1;
  173. }
  174. }
  175. }
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182. void sqaurea(void)
  183. {
  184. for (int j = 0; j < 9; j++)
  185. {
  186. if (a[j] == 1)
  187. {
  188. for (int i = 0; i < 9; i++)
  189.  
  190. {
  191. if (a[i] == 1)
  192. {
  193. b[i+j]++;
  194. }
  195. }
  196.  
  197. }
  198. }
  199. }
  200.  
  201. void printb(void)
  202. {
  203. cout << "b[]=";
  204. for (int i = 19; i > -1; i--) cout << b[i];
  205. cout << endl;
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement