Advertisement
bero_0401

Methods

Aug 15th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | Source Code | 0 0
  1. using System.Runtime;
  2.  
  3. namespace CsharpCourse
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.  
  10.             int n = int.Parse(Console.ReadLine());
  11.             int[] arr = new int[n];
  12.             for(int i = 0; i<arr.Length; i++)
  13.             {
  14.                 arr[i] = int.Parse(Console.ReadLine());
  15.             }
  16.             CalcAvg(arr);
  17.             CalcAvg(arr , printSum: true);
  18.         }
  19.  
  20.         static double CalcAvg(int[]arr , bool printAvg = false , bool printSum = false )
  21.         {
  22.             int sum = 0;
  23.             foreach (int i in arr)
  24.             {
  25.                 sum += i;
  26.             }
  27.             double avg = sum / arr.Length;
  28.             if(printAvg) {
  29.                 Console.WriteLine(avg);
  30.             }
  31.             if (printSum)
  32.             {
  33.                 Console.WriteLine(sum);
  34.             }
  35.             return avg;
  36.            
  37.         }
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement