Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define SIZE 100
- void chen (char S[], int k);
- void chuanHoa (char S1[], char S2[]);
- void tinhTong(char S1[], char S2[], char S[]);
- void main()
- {
- char S1[SIZE], S2[SIZE], S[SIZE];
- printf ("Nhap lan luot 2 so !\n");
- gets(S1);
- gets(S2);
- chuanHoa (S1,S2);
- tinhTong(S1, S2, S);
- puts(S);
- }
- void chen (char S[], int k)
- {
- strrev (S);
- int l=strlen(S);
- for (int i=0;i<k;i++)
- {
- S[l+i]='0';
- }
- S[l+k]='\0';
- strrev (S);
- }
- void chuanHoa (char S1[], char S2[])
- {
- int l1=strlen (S1);
- int l2=strlen (S2);
- if (l1>l2)
- {
- chen (S2,l1-l2);
- } else
- {
- chen (S1,l2-l1);
- }
- }
- void tinhTong(char S1[], char S2[], char S[])
- {
- //chuanHoa (S1,S2);
- strrev(S1);
- strrev(S2);
- int l = strlen(S1);
- int nho = 0;
- for (int i = 0; i < l; i++)
- {
- int t = (S1[i] - '0') + (S2[i] - '0') + nho;
- if (t < 10)
- {
- S[i] = t + '0';
- nho=0;
- } else
- {
- S[i] = t - 10 + '0';
- nho = 1;
- }
- }
- if (nho==1)
- {
- S[l++]='1';
- }
- S[l] = '\0';
- strrev(S);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement