Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApplication1
- {
- class Program
- {
- //Дан массив A, состоящий из n элементов. Сформируйте «сглаженный» массив, заменив в исходном все элементы, кроме крайних, по формуле Ai = (Ai-1+Ai + Ai+1)/3 (i=2,3,...n-1)
- static void New_Array(int[] array)
- {
- int x1 = array[0];
- int x2 = 0;
- Console.WriteLine("Полученный массив:");
- for (int i = 1; i < array.Length - 1; i++)
- {
- x2 = array[i];
- array[i] = (x1 + x2 + array[i + 1]) / 3;
- x1 = x2;
- }
- foreach (int n in array)
- {
- Console.Write(n+" ");
- }
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Исходный Массив A:");
- int[] A = new int[] { 2,1,5,7,4,2,21,6,7,58,54};
- foreach(int n in A)
- {
- Console.Write(n+" ");
- }
- Console.WriteLine();
- New_Array(A);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement