Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // флаг -с - считка чисел с консоли
- // флаг -f <filename> - считка с файла filename
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace lab04_a_
- {
- class Program
- {
- static void Main(string[] args)
- {
- var nums = new string [255] ;
- if (args.Length == 0) nums =Console.ReadLine().Split(new Char[] { ' ' });
- else if (args[0] == "-c") nums = Console.ReadLine().Split(new Char[] { ' ' });
- else if (args[0] == "-f")
- {
- var file = new System.IO.StreamReader(args[1]);
- string line;
- string buf = " ";
- while ((line = file.ReadLine()) != null) { buf += line; }
- nums = buf.Split(new Char[] { ' ' });
- }
- int i = 0;
- double res = 0;
- foreach (var n in nums)
- {
- double temp = 0;
- double.TryParse(n, out temp);
- res += temp;
- if (!string.IsNullOrWhiteSpace(n)) i++;
- }
- res /= i;
- Console.WriteLine(res);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement