Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApplication1
- {
- class Program
- {
- //А1 – А2 + А3 – ... + (–1)N-1АN.
- static double Calculation(int n, int[] array)
- {
- double s = 0;
- for(int i = 0; i<n;i++)
- {
- if (i % 2 == 1)
- {
- s += array[i];
- }
- else
- {
- s -= array[i];
- }
- }
- return s;
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Введите количество используемых значений в рассчёте :");
- int n = Int32.Parse(Console.ReadLine());
- Random random = new Random();
- int[] array = new int[1000];
- Console.WriteLine("Использумые значения:");
- for (int i = 0; i<n;i++)
- {
- array[i] = random.Next(-100, 100);
- Console.Write(array[i] + " ");
- }
- Console.WriteLine("\nРезультат вычисления");
- Console.WriteLine(Calculation(n,array));
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement