Advertisement
BojidarDosev

Untitled

Mar 7th, 2021
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. static int[] ar1 = new int[] { 4, 5, 3 };
  2. static int[] ar2 = new int[] { 5, 7, 8};
  3. static int[] ar3 = new int[10];
  4.  
  5. static void Sum()
  6. {
  7. int c = 0;
  8. int i = 0;
  9. while (i < ar1.Length && i< ar2.Length)
  10. {
  11. int d = ar1[i] + ar2[i];
  12. if (d >= 10)
  13. {
  14. d %= 10;
  15. ar3[i] = d + c;
  16. c = 1;
  17. }
  18. else
  19. {
  20. ar3[i] = d + c;
  21. c = 0;
  22. }
  23. i++;
  24. }
  25. if (ar1.Length > ar2.Length)
  26. {
  27. int a = i;
  28. for(; a<ar1.Length; a++)
  29. {
  30. ar3[a] = ar1[a] + c;
  31. c = 0;
  32. }
  33. i = a;
  34. }
  35. if (ar2.Length > ar1.Length)
  36. {
  37. int a = i;
  38. for(; a < ar2.Length; a++)
  39. {
  40. ar3[a] = ar2[a] + c;
  41. c = 0;
  42. }
  43. i = a;
  44. }
  45.  
  46. Console.WriteLine();
  47. int j = i-1;
  48. if (c == 1)
  49. {
  50. ar3[i] = 1;
  51. j = i;
  52.  
  53. }
  54. for (; j>=0 ; j--)
  55. {
  56. Console.Write(ar3[j]);
  57. }
  58. Console.WriteLine();
  59. }
  60.  
  61. static void Ar(int[] a)
  62. {
  63. for (int i = a.Length-1 ; i>=0 ; i--)
  64. Console.Write(a[i]);
  65. }
  66. static void Main(string[] args)
  67. {
  68. Ar(ar1);
  69. Console.WriteLine();
  70. Ar(ar2);
  71. Sum();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement