Advertisement
BojidarDosev

zad 8

Feb 28th, 2021
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static int[] ar1 = new int[] { 4, 5, 3, 0, 1 };
  8.         static int[] ar2 = new int[] { 5, 7, 8, 1, 2 };
  9.         static int[] ar3 = new int[10];
  10.    
  11.         static void Sum()
  12.         {
  13.             int c = 0;
  14.             int i = 0;
  15.             while (i < ar1.Length && i< ar2.Length)
  16.             {
  17.                 int d = ar1[i] + ar2[i];
  18.                 if (d >= 10)
  19.                 {
  20.                     d %= 10;
  21.                     ar3[i] = d + c;
  22.                     c = 1;
  23.                 }
  24.                 else
  25.                 {
  26.                     ar3[i] = d + c;
  27.                     c = 0;
  28.                 }
  29.             }
  30.  
  31.             if (c == 1) ar3[i] = 1;
  32.             for (int j = 0;  j< i ; j++)
  33.             {
  34.                 Console.Write(ar3[j]);
  35.             }
  36.             Console.WriteLine();
  37.         }
  38.         static void Ar(int[] a)
  39.         {
  40.             for (int i = 0; i < a.Length; i++)
  41.                 Console.Write(a[i]);
  42.         }
  43.         static void Main(string[] args)
  44.         {
  45.             Ar(ar1);
  46.             Console.WriteLine();
  47.             Ar(ar2);
  48.             Sum();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement