Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int[] ar1 = new int[] { 4, 5, 3 };
- static int[] ar2 = new int[] { 5, 7, 8};
- static int[] ar3 = new int[10];
- static void Sum()
- {
- int c = 0;
- int i = 0;
- while (i < ar1.Length && i< ar2.Length)
- {
- int d = ar1[i] + ar2[i];
- if (d >= 10)
- {
- d %= 10;
- ar3[i] = d + c;
- c = 1;
- }
- else
- {
- ar3[i] = d + c;
- c = 0;
- }
- i++;
- }
- if (ar1.Length > ar2.Length)
- {
- int a = i;
- for(; a<ar1.Length; a++)
- {
- ar3[a] = ar1[a] + c;
- c = 0;
- }
- i = a;
- }
- if (ar2.Length > ar1.Length)
- {
- int a = i;
- for(; a < ar2.Length; a++)
- {
- ar3[a] = ar2[a] + c;
- c = 0;
- }
- i = a;
- }
- Console.WriteLine();
- int j = i-1;
- if (c == 1)
- {
- ar3[i] = 1;
- j = i;
- }
- for (; j>=0 ; j--)
- {
- Console.Write(ar3[j]);
- }
- Console.WriteLine();
- }
- static void Ar(int[] a)
- {
- for (int i = a.Length-1 ; i>=0 ; i--)
- Console.Write(a[i]);
- }
- static void Main(string[] args)
- {
- Ar(ar1);
- Console.WriteLine();
- Ar(ar2);
- Sum();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement