Guest User

Chia Số Nguyên Lớn

a guest
May 6th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4. char a[1000], b[1000], c[1000];
  5. int temp = 0, d = 0, t = 0;
  6. void tru(char a[], char b1[]){
  7. char temp[1000];
  8. char b[1000];
  9. strcpy(b,b1);
  10. strrev(a);
  11. strrev(b);
  12. while(strlen(a) < strlen(b))
  13. strcat(a,"0");
  14. while(strlen(a) > strlen(b))
  15. strcat(b,"0");
  16. int n = strlen(a), m = strlen(b);
  17. int t, nho = 0;
  18. char hieu[1000];
  19. for(int i= 0; i <= n; i++){
  20. int a1 = a[i] - '0';
  21. int b1 = b[i] - '0';
  22. if(a1 - nho >= b1){
  23. t = (a1 - b1 - nho) % 10;
  24. nho = 0;
  25. }
  26. else{
  27. t = ((a1 + 10)- b1 - nho) % 10;
  28. nho = 1;
  29. }
  30. hieu[i] = t + '0';
  31. }
  32. if(hieu[n - 1] == '0')
  33. hieu[n - 1] = '\0';
  34. else
  35. hieu[n] = '\0';
  36. strrev(hieu);
  37. strcpy(a,hieu);
  38. }
  39.  
  40. int AbiggerthanB(char a[], char b[]){
  41. // xem a co con lon hon b khong. neu nho hon thi dung
  42. if(strlen(a) < strlen(b))
  43. return 0;
  44. if(strlen(a) == strlen(b)){
  45. for(int i = 0; i < strlen(a); i++){
  46. if(a[i] > b[i])
  47. return 1;
  48. if(a[i] < b[i])
  49. return 0;
  50. }
  51. }
  52. return 1;
  53. }
  54.  
  55. void chia(char a[], char b[]){
  56. int m = strlen(a), n = strlen(b);
  57. if(m >= n){
  58. while(AbiggerthanB(a,b)){
  59. // printf("a = %s \n", a);
  60. temp++;
  61. tru(a,b);
  62. // printf("a = %s b = %s \n", a, b);
  63. // printf("lengh A = %d lengh B = %d", strlen(a), strlen(b));
  64. }
  65. }
  66.  
  67. printf("Thuong a/b: %d\n", temp);
  68. printf("So du = %s\n", a);
  69. //
  70. }
  71.  
  72. void Nhap(){
  73. printf("Nhap vao so a:");
  74. gets(a);
  75. fflush(stdin);
  76. printf("Nhap vao so b:");
  77. gets(b);
  78. chia(a,b);
  79. }
  80.  
  81.  
  82.  
  83. main(){
  84. Nhap();
  85. chia(a,b);
  86. // Out();
  87. }
Advertisement
Add Comment
Please, Sign In to add comment