Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 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 algoIIa1
  8. {
  9.     class Program
  10.     {
  11.         public static int a1(int i) {
  12.             if (i == 0) return 7;
  13.             else if (i == 1) return 1;
  14.             else if (i == 2) return 5;
  15.             else {
  16.                 if (i % 2 == 0)
  17.                 {
  18.                     return (int)Math.Pow(a1(i - 3) + a1(i - 2), 2) + a1(i - 1);
  19.                 }
  20.                 else {
  21.                     return (int)Math.Pow(a1(i - 3) - a1(i - 2), 2) + a1(i - 1);
  22.                 }
  23.             }
  24.         }
  25.         public static int a2(int szam, int db) {
  26.             if (db == 1) return szam;
  27.             else return szam + a2(szam, db - 1);
  28.         }
  29.  
  30.         static void a3(List<int> rendezni)
  31.         {
  32.             if (rendezni.Count > 1)
  33.             {
  34.                 int Max = rendezni.Max();
  35.                 rendezni.Remove(Max);
  36.                 a3(rendezni);
  37.                 rendezni.Insert(0, Max);
  38.             }
  39.         }
  40.         static void Main(string[] args)
  41.         {
  42.             Console.WriteLine("Első feladat: ");
  43.             Console.WriteLine(a1(3).ToString());
  44.             Console.WriteLine("Második feladat: ");
  45.             Console.WriteLine(a2(3,3).ToString());
  46.             Console.WriteLine("Harmadik feladat: ");
  47.             List<int> rendezni = new List<int>() {3,5,6,1,10,9,6,7,8 };
  48.             a3(rendezni);
  49.             foreach (var item in rendezni)
  50.             {
  51.                 Console.Write("{0},",item);
  52.             }
  53.             Console.ReadLine();
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement