Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Drafty
- {
- class Program
- {
- public static double Calculate(int[] values)
- {
- if (values.Length <= 1)
- {
- throw new ArgumentException("должно быть хотя бы два числа");
- }
- double q = values[1] / values[0];
- if (q == 1)
- {
- throw new ArgumentException("Прогрессия не является геометрической");
- }
- return (double) (values[0] * (1d - Math.Pow(q, values.Length))) / (double) (1d - q);
- }
- public static double GetSum(params int[] values)
- {
- try
- {
- return Calculate(values);
- }
- catch (ArgumentException ex)
- {
- Console.WriteLine("Ошибка: " + ex.Message);
- }
- return -1;
- }
- static void Main(string[] args)
- {
- Console.WriteLine(
- GetSum(81)
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment