Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ArrSumElement
- {
- class Program
- {
- static int Sum(int arr)
- {
- int num = arr;
- int sumDigit = 0;
- while (num != 0)
- {
- sumDigit += num % 10;
- num /= 10;
- }
- return arr;
- }
- static int FunSum(int num)
- {
- return ((num / 10) + (num % 10));
- }
- static void Main(string[] args)
- {
- int[] A = { 24, 15, 83, 36 };
- int sumArr = 0;
- Console.WriteLine("Arr:");
- for (int i = 0; i < A.Length; i++)
- {
- Console.Write($"[{A[i]}]");
- }
- Console.WriteLine("\n");
- for (int i = 0; i < A.Length; i++)
- {
- int sum = FunSum(A[i]);
- sumArr += Sum(A[i]);
- Console.WriteLine($"Для элемента [{A[i]}] сумма чисел: {sum}");
- }
- Console.WriteLine($"Cумма всех чисел элементов массива: {sumArr}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement