Advertisement
StreetKatya

Саня и Ромб

Feb 20th, 2023
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Саня_и_Ромб
  8. {
  9.     internal class Program
  10.     {
  11.         /*
  12.          
  13.                                  IV
  14.                        III        0
  15.                 II      0        000
  16.           I     0      000      00000
  17.           0 -> 000 -> 00000 -> 0000000
  18.           1     0      000      00000
  19.            ---> 5       0        000
  20.             +4   -----> 13        0
  21.                    +8     ------> 25  
  22.                             +12
  23.          */
  24.         static void Main(string[] args)
  25.         {
  26.             Console.WriteLine("Введите порядок ромба");
  27.             int n = int.Parse(Console.ReadLine());
  28.             int res = Calculate(n);
  29.             Console.WriteLine(res);
  30.             Console.ReadKey();
  31.         }
  32.         public static int Calculate(int n)
  33.         {
  34.             int result = 1;
  35.             int temp = 0;
  36.             for (int i = 1; i < n; i++)
  37.             {
  38.                 temp += 4;
  39.                 result += temp;
  40.             }
  41.             return result;
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement