Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace algoIIa1
- {
- class Program
- {
- public static int a1(int i) {
- if (i == 0) return 7;
- else if (i == 1) return 1;
- else if (i == 2) return 5;
- else {
- if (i % 2 == 0)
- {
- return (int)Math.Pow(a1(i - 3) + a1(i - 2), 2) + a1(i - 1);
- }
- else {
- return (int)Math.Pow(a1(i - 3) - a1(i - 2), 2) + a1(i - 1);
- }
- }
- }
- public static int a2(int szam, int db) {
- if (db == 1) return szam;
- else return szam + a2(szam, db - 1);
- }
- static void a3(List<int> rendezni)
- {
- if (rendezni.Count > 1)
- {
- int Max = rendezni.Max();
- rendezni.Remove(Max);
- a3(rendezni);
- rendezni.Insert(0, Max);
- }
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Első feladat: ");
- Console.WriteLine(a1(3).ToString());
- Console.WriteLine("Második feladat: ");
- Console.WriteLine(a2(3,3).ToString());
- Console.WriteLine("Harmadik feladat: ");
- List<int> rendezni = new List<int>() {3,5,6,1,10,9,6,7,8 };
- a3(rendezni);
- foreach (var item in rendezni)
- {
- Console.Write("{0},",item);
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement