Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- char a[51], b[51], c[52];
- int i,j,k,atvitel,osszeg;
- while(scanf("%s + %s",a,b) != EOF)
- {
- printf("*%s*\n",a);
- printf("*%s*\n",b);
- printf("\n");
- i=strlen(a)-1;
- j=strlen(b)-1;
- printf("i=%d\tj=%d\n",i,j);
- atvitel=0, k=0;
- while(i>=0 && j>=0)
- {
- int osszeg = (a[i]-'0') + (b[j]-'0') + atvitel;
- int szamjegy = osszeg % 10;
- atvitel = osszeg / 10;
- printf("%d\n",szamjegy);
- c[k++]=szamjegy+'0';
- i-- , j--;
- }
- while(j>=0)
- {
- int osszeg = (b[j]-'0') + atvitel;
- int szamjegy = osszeg % 10;
- atvitel = osszeg / 10;
- printf("%d\n",szamjegy);
- c[k++]=szamjegy+'0';
- j--;
- }
- while(i>=0)
- {
- int osszeg = (a[i]-'0') + atvitel;
- int szamjegy = osszeg % 10;
- atvitel = osszeg / 10;
- printf("%d\n",szamjegy);
- c[k++]=szamjegy+'0';
- i--;
- }
- if (atvitel>0)
- {
- printf("%d\n",atvitel);
- c[k++]=atvitel+'0';
- }
- printf("\n");
- c[k]='\0';
- printf("%s\n",c);
- for (i=0,j=strlen(c)-1; i<j; i++,j--)
- {
- char seged;
- seged = c[i];
- c[i] = c[j];
- c[j] = seged;
- }
- printf("%s\n",c);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement