Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<math.h>
- char a[1000], b[1000], c[1000];
- int temp = 0, d = 0, t = 0;
- void tru(char a[], char b1[]){
- char temp[1000];
- char b[1000];
- strcpy(b,b1);
- strrev(a);
- strrev(b);
- while(strlen(a) < strlen(b))
- strcat(a,"0");
- while(strlen(a) > strlen(b))
- strcat(b,"0");
- int n = strlen(a), m = strlen(b);
- int t, nho = 0;
- char hieu[1000];
- for(int i= 0; i <= n; i++){
- int a1 = a[i] - '0';
- int b1 = b[i] - '0';
- if(a1 - nho >= b1){
- t = (a1 - b1 - nho) % 10;
- nho = 0;
- }
- else{
- t = ((a1 + 10)- b1 - nho) % 10;
- nho = 1;
- }
- hieu[i] = t + '0';
- }
- if(hieu[n - 1] == '0')
- hieu[n - 1] = '\0';
- else
- hieu[n] = '\0';
- strrev(hieu);
- strcpy(a,hieu);
- }
- int AbiggerthanB(char a[], char b[]){
- // xem a co con lon hon b khong. neu nho hon thi dung
- if(strlen(a) < strlen(b))
- return 0;
- if(strlen(a) == strlen(b)){
- for(int i = 0; i < strlen(a); i++){
- if(a[i] > b[i])
- return 1;
- if(a[i] < b[i])
- return 0;
- }
- }
- return 1;
- }
- void chia(char a[], char b[]){
- int m = strlen(a), n = strlen(b);
- if(m >= n){
- while(AbiggerthanB(a,b)){
- // printf("a = %s \n", a);
- temp++;
- tru(a,b);
- // printf("a = %s b = %s \n", a, b);
- // printf("lengh A = %d lengh B = %d", strlen(a), strlen(b));
- }
- }
- printf("Thuong a/b: %d\n", temp);
- printf("So du = %s\n", a);
- //
- }
- void Nhap(){
- printf("Nhap vao so a:");
- gets(a);
- fflush(stdin);
- printf("Nhap vao so b:");
- gets(b);
- chia(a,b);
- }
- main(){
- Nhap();
- chia(a,b);
- // Out();
- }
Advertisement
Add Comment
Please, Sign In to add comment