-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlgorithms.cs
124 lines (106 loc) · 3.54 KB
/
Algorithms.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace Algoritmalar
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("1. Çift sayıları yazdırma");
Console.WriteLine("2. Bölme sorusu");
Console.WriteLine("3. Sondan başa doğru liste yazdırma");
Console.WriteLine("4. Cümledeki toplam kelime ve harf");
Console.WriteLine("Görüntülemek istediğiniz soruyu seçiniz:");
int secim = Convert.ToInt32(Console.ReadLine());
questions soru = new questions();
switch (secim)
{
case 1:
soru.IsEvenList();
break;
case 2:
soru.dividingOrNot();
break;
case 3:
soru.fromlasttofirst();
break;
case 4:
soru.CounterOfWord();
break;
default:
Console.WriteLine("Yanlış seçim yaptınız.");
break;
}
}
}
class questions
{
public void IsEvenList()
{
Console.Write("Sayı Adedini Giriniz : ");
string n = Console.ReadLine();
List<int> sayilar = new List<int>();
for (int i = 0; i < int.Parse(n); i++)
{
Console.Write((i+1)+". Sayıyı Giriniz : ");
int sayi = int.Parse(Console.ReadLine());
if (sayi % 2 == 0) sayilar.Add(sayi);
}
foreach(var m in sayilar)
{
Console.WriteLine(m);
}
}
public void dividingOrNot()
{
Console.Write("Bölen değerini giriniz : ");
int m = int.Parse(Console.ReadLine());
Console.Write("Sayı Adedini Giriniz : ");
int n = int.Parse(Console.ReadLine());
List<int> sayilar = new List<int>();
for (int i=0; i<n;i++)
{
Console.Write((i+1) + ". Sayıyı Giriniz : ");
int sayi = int.Parse(Console.ReadLine());
if (m % sayi == 0) sayilar.Add(sayi);
}
foreach (var j in sayilar)
{
Console.WriteLine(j);
}
}
public void fromlasttofirst()
{
Console.Write("Kelime Adedini Giriniz : ");
int n = int.Parse(Console.ReadLine());
List<string> kelimeler = new List<string>();
for (int i = 0; i < n; i++)
{
Console.Write("Sayi Giriniz : ");
string kelime = Console.ReadLine();
kelimeler.Add(kelime);
}
for (int i = n - 1; i >= 0; i--)
{
Console.WriteLine(kelimeler[i]);
}
/*
foreach (var kelime in kelimeler)
Console.WriteLine(kelime);
Console.WriteLine(Array.Reverse(kelimeler));
*/
}
public void CounterOfWord()
{
Console.Write("Cümle veya kelime Giriniz : ");
string cumle = Console.ReadLine();
string[] kelimeler = cumle.Split(' ');
Console.WriteLine("Kelime Sayisi : {0}",kelimeler.Count());
Console.WriteLine("Harf Sayisi : {0}", cumle.Count());
}
}
}