Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7. char a[51], b[51], c[52];
  8. int i,j,k,atvitel,osszeg;
  9.  
  10.  
  11. while(scanf("%s + %s",a,b) != EOF)
  12. {
  13. printf("*%s*\n",a);
  14. printf("*%s*\n",b);
  15. printf("\n");
  16.  
  17. i=strlen(a)-1;
  18. j=strlen(b)-1;
  19. printf("i=%d\tj=%d\n",i,j);
  20.  
  21.  
  22.  
  23. atvitel=0, k=0;
  24. while(i>=0 && j>=0)
  25. {
  26. int osszeg = (a[i]-'0') + (b[j]-'0') + atvitel;
  27. int szamjegy = osszeg % 10;
  28. atvitel = osszeg / 10;
  29. printf("%d\n",szamjegy);
  30. c[k++]=szamjegy+'0';
  31. i-- , j--;
  32. }
  33.  
  34. while(j>=0)
  35. {
  36. int osszeg = (b[j]-'0') + atvitel;
  37. int szamjegy = osszeg % 10;
  38. atvitel = osszeg / 10;
  39. printf("%d\n",szamjegy);
  40. c[k++]=szamjegy+'0';
  41. j--;
  42. }
  43.  
  44. while(i>=0)
  45. {
  46. int osszeg = (a[i]-'0') + atvitel;
  47. int szamjegy = osszeg % 10;
  48. atvitel = osszeg / 10;
  49. printf("%d\n",szamjegy);
  50. c[k++]=szamjegy+'0';
  51. i--;
  52.  
  53. }
  54.  
  55. if (atvitel>0)
  56. {
  57. printf("%d\n",atvitel);
  58. c[k++]=atvitel+'0';
  59. }
  60.  
  61. printf("\n");
  62. c[k]='\0';
  63. printf("%s\n",c);
  64.  
  65.  
  66.  
  67.  
  68. for (i=0,j=strlen(c)-1; i<j; i++,j--)
  69. {
  70. char seged;
  71. seged = c[i];
  72. c[i] = c[j];
  73. c[j] = seged;
  74. }
  75. printf("%s\n",c);
  76. }
  77.  
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement