Advertisement
ElliasBLR

laba4Ksenia

Mar 4th, 2021
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApplication1
  4. {
  5.  
  6.     class Program
  7.     {
  8.  
  9.         //А1 – А2 + А3 – ... + (–1)N-1АN.
  10.  
  11.  
  12.  
  13.         static double Calculation(int n, int[] array)
  14.         {
  15.             double s = 0;
  16.             for(int i = 0; i<n;i++)
  17.             {
  18.                 if (i % 2 == 1)
  19.                 {
  20.                     s += array[i];
  21.                 }
  22.                 else
  23.                 {
  24.                     s -= array[i];
  25.                 }
  26.             }
  27.             return s;
  28.         }
  29.        
  30.  
  31.         static void Main(string[] args)
  32.         {
  33.             Console.WriteLine("Введите количество используемых значений в рассчёте :");
  34.             int n = Int32.Parse(Console.ReadLine());
  35.             Random random = new Random();
  36.             int[] array = new int[1000];
  37.             Console.WriteLine("Использумые значения:");
  38.             for (int i = 0; i<n;i++)
  39.             {
  40.                 array[i] = random.Next(-100, 100);
  41.                 Console.Write(array[i] + " ");
  42.  
  43.             }
  44.            
  45.  
  46.             Console.WriteLine("\nРезультат вычисления");
  47.             Console.WriteLine(Calculation(n,array));
  48.  
  49.             Console.ReadKey();
  50.  
  51.         }
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement