Есть ответ 👍

Дано целое число n. определите среднее арифметическое нечётных цифр числа.

155
180
Посмотреть ответы 2

Ответы на вопрос:


Program lol (input, output); var a, n, b, i, p,s, m: integer; c: real; begin read (n); a: =n; b: =0; c: =0; i: =0; p: =1; while a < > 0 do begin a: =a div 10; b: =b+1; end; while b < > 0 do begin p: =1; for m: =1 to b do p: =p*10; s: =(n mod p) div (p div 10); if (s mod 2) < > 0 then begin c: =c+s; i: =i+1; end; b: =b-1; end; c: =c/i; writeln (c); end.
lbogdan2
4,4(48 оценок)

--- C# 7.3 -- (.NET Framework 4.8)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace CSLear

{

   class Program

   {

       static void Main(string[] args)

       {

           Tuple<int, int> MatrixRange = new Tuple<int, int>(-10, 10);

           int M = int.Parse(Console.ReadLine());

           int N = int.Parse(Console.ReadLine());

           int[,] Arr = new int[M,N];

           ArrayRandomize(ref Arr, M, N, MatrixRange);

           MatrixPrint(Arr, M, N);

           int Negatives = Arr.Count(x => x < 0);

           int Zero = Arr.Count(x => x == 0);

           int Positives = Arr.Count(x => x > 0);

           Console.WriteLine($"Positive Items: {Positives}\nNegative Items: {Negatives}\nZeroes: {Zero}");

           Console.ReadKey();

       }

       public static void MatrixPrint<T>(T[,] Matrix, int MRows, int MCols)

       {

           StringBuilder sb = new StringBuilder();

           for (int i = 0; i < MRows; i++)

           {

               for (int j = 0; j < MCols; j++)

               {

                   sb.Append($"{Matrix[i, j]} ");

               }

               sb.Append("\n");

           }

           Console.WriteLine(sb.ToString());

       }

       public static void ArrayRandomize(ref int[,] Arr, int ArrRows, int ArrCols, Tuple<int, int> Range)

       {

           Random r = new Random();

           for (int i = 0; i < ArrRows; i++)

           {

               for (int j = 0; j < ArrCols; j++)

               {

                   Arr[i, j] = r.Next(Range.Item1, Range.Item2);

               }

           }

       }

   public static class Extensions

   {

       public static int Count<T>(this T[,] Matr, Func<T, bool> Predicate)

       {

           int counter = 0;

           foreach (T Item in Matr)

           {

               if (Predicate(Item)) counter++;

           }

           return counter;

       }

   }

}

Объяснение:

Популярно: Информатика