Advertisement
Guest User

bitch

a guest
Oct 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /* Print the decimal representation of N/D with up to
  5. P digits after the decimal point.
  6. */
  7. #define P 59
  8. void *safeMalloc(int n) {
  9. void *p = malloc(n);
  10. if (p == NULL) {
  11. printf("Error: malloc(%d) failed. Out of memory?\n", n);
  12. exit(EXIT_FAILURE);
  13. }
  14. return p;
  15. }
  16.  
  17.  
  18.  
  19. void PrintDecimal(unsigned N, unsigned D)
  20. {
  21. unsigned *array[60];
  22. unsigned tailing;
  23. unsigned bitch;
  24. unsigned firstindex;
  25. unsigned lastindex;
  26. // array=safeMalloc(100);
  27. int j=0;
  28.  
  29. // Print the integer portion.
  30. // printf("%u.", N/D);
  31.  
  32. // Take the remainder.
  33. N %= D;
  34. array[j]=N;
  35. j++;
  36. printf("this is the first remainder in the array:%d\n",array[0]);
  37. // printf("this is the remainder%d\n",N);
  38. for (int i = 0; i < P && (N!=0); ++i)
  39. {
  40. // Move to next digit position and print next digit.
  41. N *= 10;
  42. // printf("%u", N/D);
  43.  
  44. // Take the remainder.
  45. N %= D;
  46. for(int k=0;k<=j;k++)
  47. {
  48. if(N==array[k])
  49. {
  50. firstindex=k;
  51. lastindex=j;
  52. }
  53. else{ array[j]=N;}
  54.  
  55. }
  56. // printf("This is the remainder that goes in the array:%d\n",N);
  57.  
  58. j++;
  59.  
  60.  
  61. }
  62. // printf("\n%d\n",k);
  63. for(int p=0;p<j;p++)
  64. {
  65. // printf("%u ",array[p]);
  66. tailing=array[p];
  67. bitch=(tailing*10)/D;
  68.  
  69.  
  70. printf("%u ",bitch);
  71.  
  72. }
  73. putchar('\n');
  74.  
  75.  
  76.  
  77. }
  78.  
  79.  
  80. int main()
  81. {
  82. int denom,numerator;
  83. scanf("%d",&denom);
  84. scanf("%d",&numerator);
  85. PrintDecimal(denom, numerator);
  86. putchar('\n');
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement