├── Hafta1 ├── a.out ├── dnm1.cpp ├── integers2.cpp ├── chars.cpp ├── dnm1.s ├── integers.cpp ├── floats.cpp └── strings.cpp ├── Hafta2 ├── a.out ├── bool-input.cpp ├── arttirma_operatoru.cpp ├── for-4.cpp ├── while2.cpp ├── for-2.cpp ├── if-else4.cpp ├── array2.cpp ├── while.cpp ├── array1.cpp ├── for-5.cpp ├── input2.cpp ├── if-else3.cpp ├── for-3.cpp ├── for-1.cpp ├── input1.cpp ├── if-else2.cpp └── if-else1.cpp ├── Hafta3 ├── a.out ├── toplambitsayisi-fonksiyonlar4.cpp ├── stringIslemleri.cpp ├── array2.cpp ├── fonksiyonlar1.cpp ├── palindromestring-fonksiyonlar3.cpp ├── asalsayi-fonksiyonlar.cpp ├── fonksiyonlar2.cpp ├── array1.cpp ├── stringIslemleri2.cpp └── asalcarpanlar-fonksiyonlar2.cpp ├── Hafta4 ├── a.out ├── recursion_fibonacci.cpp ├── pointer2.cpp ├── pointer4.cpp ├── pointer.cpp ├── two_dimensional_array.cpp ├── recursion_1.cpp └── pointer3.cpp ├── Hafta5 ├── a.out ├── coutputislemleri.cpp ├── strings.cpp ├── 2dvectors.cpp ├── 2darrays.cpp ├── vectors.cpp ├── bubblesort.cpp ├── fibonacci.cpp └── taskagitmakas.cpp └── Hafta6 ├── a.out ├── Class ├── a.out ├── class-java-stil-constructor.cpp ├── class-2.cpp ├── class-1.cpp ├── class-3.cpp └── linked-list-1.cpp ├── Sorular ├── a.out ├── getline.cpp ├── auto.cpp ├── fibo.cpp └── insertion_sort.cpp └── memsets.cpp /Hafta1/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r0-zero/Compec-Cpp-2021/master/Hafta1/a.out -------------------------------------------------------------------------------- /Hafta2/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r0-zero/Compec-Cpp-2021/master/Hafta2/a.out -------------------------------------------------------------------------------- /Hafta3/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r0-zero/Compec-Cpp-2021/master/Hafta3/a.out -------------------------------------------------------------------------------- /Hafta4/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r0-zero/Compec-Cpp-2021/master/Hafta4/a.out -------------------------------------------------------------------------------- /Hafta5/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r0-zero/Compec-Cpp-2021/master/Hafta5/a.out -------------------------------------------------------------------------------- /Hafta6/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r0-zero/Compec-Cpp-2021/master/Hafta6/a.out -------------------------------------------------------------------------------- /Hafta6/Class/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r0-zero/Compec-Cpp-2021/master/Hafta6/Class/a.out -------------------------------------------------------------------------------- /Hafta6/Sorular/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r0-zero/Compec-Cpp-2021/master/Hafta6/Sorular/a.out -------------------------------------------------------------------------------- /Hafta1/dnm1.cpp: -------------------------------------------------------------------------------- 1 | 2 | int main() 3 | { 4 | int xx = 5 * 10 + 10 - 5 + 3; 5 | 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Hafta3/toplambitsayisi-fonksiyonlar4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int n; cin >> n; 8 | 9 | cout << __builtin_popcount(n) << endl; 10 | cout << __builtin_parity(n) << endl; 11 | 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Hafta2/bool-input.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | bool deneme; 7 | cin >> deneme; 8 | 9 | // C++ ta bool deger eger kullanicidan okunacaksa 0 yada 1 girilmeli. 10 | cout << deneme << endl; 11 | 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Hafta2/arttirma_operatoru.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int i = 1; 8 | 9 | // Once arttirma sonra sayiyi yazdirir 10 | cout << ++i << endl; 11 | // Once sayiyi yazdirir sonra arttirmayi yapar 12 | cout << i++ << endl; 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Hafta2/for-4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | string s = "Compec2021"; 8 | 9 | cout << s.size() << endl; 10 | cout << s[1] << endl; 11 | cout << sizeof(s[0]) << endl; 12 | 13 | for (int i=0; i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string s = "Compec"; 7 | int i = 0; 8 | 9 | while (1) 10 | { 11 | cout << s << endl; 12 | i++; 13 | 14 | // break loopu kirmak icin kullanilir 15 | if (i == 100) 16 | { 17 | break; 18 | } 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Hafta6/memsets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | // c stili string, char arr[] sonuna \0 9 | char arr[500]; 10 | memset(arr, 'a', sizeof(arr)); 11 | //Alttaki onemli 12 | // arr[499] = '\0'; 13 | 14 | cout << arr << endl; 15 | 16 | 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Hafta1/integers2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | short int x = 32767; 8 | 9 | cout << x << endl; 10 | 11 | x = x + 1; 12 | 13 | // Integer overflow 14 | cout << x << endl; 15 | 16 | 17 | unsigned short int y = 65535; 18 | 19 | y = y + 1; 20 | 21 | cout << y << endl; 22 | 23 | 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Hafta4/recursion_fibonacci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int fibo(int n) 6 | { 7 | if (n <= 1) 8 | return n; 9 | 10 | return fibo(n-2) + fibo(n-1); 11 | } 12 | 13 | 14 | int main() 15 | { 16 | cout << "Bulunmasini istediginiz fibonacci sayisini girin" << endl; 17 | int n; cin >> n; 18 | 19 | cout << fibo(n) << endl; 20 | 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Hafta5/coutputislemleri.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | // 10 27 a 1.324 8 | int x, y; 9 | char c; 10 | float z; 11 | 12 | string s1 = "COMPEC"; 13 | 14 | 15 | scanf("%d %d %c %f", &x, &y, &c, &z); 16 | 17 | printf("%f\n%c\n%d\n%d", z, c, x, y); 18 | 19 | printf("%s\n", s1.c_str()); 20 | 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Hafta2/for-2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | // 0 dan sayiya kadar simdi tersini yapicaz 8 | // Sayidan 0 a kadar yazdiracagiz 9 | 10 | cout << "Lutfen bir sayi girin" << endl; 11 | int x; 12 | cin >> x; 13 | 14 | for (int i=x-1; i>=0; i--) 15 | { 16 | cout << i << ' '; 17 | } 18 | cout << endl; 19 | 20 | 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Hafta4/pointer2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int* xptr; 8 | if (1) 9 | { 10 | // heap memoryde olusturuldu 11 | int* x = new int(10); 12 | // xptr a heap memoryde olusturdugumuz degiskenin addresini verdik 13 | xptr = x; 14 | } 15 | 16 | 17 | cout << *xptr << endl; 18 | // Dogru gosterim 19 | delete xptr; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Hafta6/Class/class-java-stil-constructor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | class Employee 6 | { 7 | int yas; 8 | string isim, soyisim; 9 | 10 | public: 11 | //2.stil, java-python stili constructor 12 | Employee(string isim, string soyisim) 13 | { 14 | this->isim = isim; 15 | this->soyisim = soyisim; 16 | } 17 | }; 18 | 19 | 20 | int main() 21 | { 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Hafta6/Sorular/getline.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | 8 | int n; 9 | 10 | cin >> n; 11 | 12 | cout << n << endl; 13 | 14 | cin.ignore(); 15 | 16 | string s; 17 | 18 | // Kullanici bosluklu bir string girdi : Merhaba Compec 19 | 20 | getline(cin, s); 21 | 22 | cout << s << endl; 23 | 24 | 25 | 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Hafta1/chars.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | char c1 = 'A' + 1; 7 | string c3 = "Ü"; 8 | cout << (int) c1 << endl; 9 | //cout << c3 << endl; 10 | 11 | char c2 = 72; 12 | cout << c2 << endl; 13 | 14 | char c4 = '1'; 15 | cout << (int) c4 << endl; 16 | 17 | string s = "Compec"; 18 | 19 | char c5 = '9'; 20 | 21 | cout << c5 - '0'; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Hafta3/stringIslemleri.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | int main() 7 | { 8 | // Compec 2021 -> getline ile okumak gerekli 9 | string isim2; 10 | cin >> isim2; 11 | // Inputtan sonra gelen ilk karakteri discard et 12 | cin.ignore(); 13 | 14 | string isim; 15 | getline(cin, isim); // \n 16 | 17 | 18 | cout << isim2 << endl; 19 | cout << isim << endl; 20 | 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Hafta5/strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | string s = "COMPEC"; 8 | 9 | cout << s << endl; 10 | 11 | // Buradan asagisi C stili stringler 12 | char s1[] = "COMPEC"; 13 | char s2[] = {'C', 'O', 'M', 'P', 'E', 'C', '\0'}; 14 | 15 | cout << s1 << endl; 16 | 17 | cout << s2 << endl; 18 | 19 | const char* s3 = "STRING"; 20 | 21 | cout << s3 << endl; 22 | 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Hafta2/if-else4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int x = 5; 8 | 9 | if (x == 5) 10 | { 11 | int y = 10; 12 | x = y; 13 | } 14 | 15 | cout << x << endl; 16 | 17 | if (x == 5) 18 | { 19 | int y = 10; 20 | } 21 | 22 | // Suslu parantezler icerisinde olusturulan tum degiskenler suslu parantez bittigi 23 | // an yok edilirler 24 | // cout << y << endl; 25 | 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Hafta2/array2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string a[] = {"asd","123"}; 7 | 8 | // cout << a[0] << endl; 9 | 10 | int yaslar[3]; 11 | 12 | cout << "Lutfen kullanicilarin yaslarini girin." << endl; 13 | 14 | int x, y, z; 15 | cin >> x >> y >> z; 16 | 17 | yaslar[0] = x; 18 | yaslar[1] = y; 19 | yaslar[2] = z; 20 | 21 | cout << x << ' ' << y << ' ' << z << endl; 22 | 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Hafta2/while.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int sayi; 8 | cin >> sayi; 9 | 10 | int i = 0; 11 | 12 | // i = i+2 -> i += 2 13 | while (i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | // 0 1 2 3 4 7 | int arr[] = {1, 2, 3, 4, 5}; 8 | int arr2[] = {1, 2, 3, 4, 5}; 9 | float arr1[] = {0.1, 0.2, 0.3, 0.4, 0.5}; 10 | // arrayler statik size lidir. 11 | 12 | cout << arr[0] << endl; 13 | 14 | cout << arr1[0] << endl; 15 | 16 | if (arr[0] == arr2[0]) 17 | { 18 | cout << "Iki elemanda birbirine esit" << endl; 19 | } 20 | 21 | 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Hafta2/for-5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define SIZE(arr) sizeof(arr)/sizeof(arr[0]) 5 | #define INTEGERINADINIDEGISTIRDIM int 6 | 7 | 8 | //SIZE(arr) -> sizeof(arr)/sizeof(arr[0]) -> copy paste 9 | int main() 10 | { 11 | int arr[] = {1,2,6,4,2,3,7,3,6,3,8989,3,1,2,3}; 12 | int n = SIZE(arr); 13 | 14 | for (int i=0; i 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | vector v = {1, 3, 8}; 9 | 10 | for (auto i : v) 11 | cout << i << ' '; 12 | 13 | 14 | for (vector::iterator it = v.begin(); it != v.end(); it++) 15 | { 16 | cout << *it << ' '; 17 | } 18 | 19 | string s = "COMPEC"; 20 | 21 | for (string::iterator it = s.begin(); it != s.end(); it++) 22 | cout << *it; 23 | 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Hafta2/input2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | // CamelCase ilk harf kucuk, ondan sonra gelen tum kelimelerin harfleri buyuk 8 | string isimSoyisim; 9 | // isim_soyisim -> python tarzi 10 | 11 | // cin >> isimSoyisim; 12 | getline(cin, isimSoyisim); // \n okumayi birakir 13 | 14 | cout << "Isminiz ve soyisminiz: " << isimSoyisim << endl; 15 | 16 | 17 | string x; 18 | 19 | cin >> x; 20 | 21 | cout << x << endl; 22 | 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Hafta4/pointer4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | void birseylerYap(int a) 7 | { 8 | cout << a << endl; 9 | // maindeki 'a' degiskeni ile fonksiyondaki a degiskeni ayni degil. addresslere bakarakda bunu anlayabiliriz 10 | cout << &a << endl; 11 | } 12 | 13 | 14 | int main() 15 | { 16 | int a = 5; 17 | cout << &a << endl; 18 | 19 | birseylerYap(a); 20 | 21 | // HATALI GOSTERIM, her zaman ayni degisken tipini kullanin 22 | void* aptr = &a; 23 | 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Hafta1/integers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int x = 300; 8 | int y = 105; 9 | int z = x + y; 10 | z = z + 5; 11 | z = z - 5; 12 | 13 | // Bir sayi 0 a bolunuyorsa runtime error alirsiniz 14 | // int yy = 1; 15 | // int zz = 0; 16 | // 17 | // cout << yy/zz << endl; 18 | 19 | int xx = 5 * 10 + 10 - 5 + 3; 20 | 21 | xx = xx/5; 22 | 23 | cout << xx << endl; 24 | 25 | int yy = 34; 26 | 27 | yy = yy / 85; 28 | 29 | cout << yy << endl; 30 | 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Hafta2/if-else3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | float x; 7 | cin >> x; 8 | 9 | // 0 disindaki tum sayilar true doner. 10 | if (x) 11 | { 12 | cout << "If'e girildi" << endl; 13 | } 14 | if (x) 15 | { 16 | cout << "If'e girildi" << endl; 17 | } 18 | 19 | bool dogrumuYanlismi = true; 20 | dogrumuYanlismi = false; 21 | 22 | cout << dogrumuYanlismi << endl; 23 | 24 | 25 | if (dogrumuYanlismi) 26 | { 27 | cout << "Dogru" << endl; 28 | } 29 | 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Hafta6/Sorular/fibo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int memo[5000]; 6 | 7 | 8 | int fibo(int n) 9 | { 10 | if (memo[n] != -1) 11 | return memo[n]; 12 | else if (n <= 1) 13 | { 14 | memo[n] = n; 15 | return memo[n]; 16 | } 17 | 18 | memo[n] = fibo(n-2) + fibo(n-1); 19 | return memo[n]; 20 | } 21 | 22 | 23 | 24 | 25 | 26 | int main() 27 | { 28 | memset(memo, -1, sizeof(memo)); 29 | int n; cin >> n; 30 | 31 | fibo(n); 32 | 33 | for (int i=0; i 2 | using namespace std; 3 | 4 | 5 | 6 | int main() 7 | { 8 | // float 32 bit, double 32 bit, long double 64bit 9 | 10 | float x = 0.2; 11 | float y = 0.5; 12 | float z = x + y; 13 | 14 | cout << x*y << endl; 15 | cout << z << endl; 16 | cout << y/x << endl; 17 | 18 | int x1 = 10; 19 | float y1 = 0.2; 20 | int y2 = 3; 21 | 22 | //cout << x1/y1 << endl; 23 | cout.precision(15); 24 | cout << fixed << (float)x1/y1 << endl; 25 | cout << double(x1)/y2 << endl; 26 | 27 | float zz = 2.0/3-1+1.0/3; 28 | 29 | cout << zz << endl; 30 | 31 | 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Hafta4/pointer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int x = 5; 8 | 9 | // STACK MEMORY 10 | int* xptr = &x; 11 | 12 | cout << xptr << endl; 13 | // * -> dereference operator 14 | // & -> address operator 15 | cout << *xptr << endl; 16 | cout << &xptr << endl; 17 | 18 | int** xptrptr = &xptr; 19 | 20 | cout << xptr << endl; 21 | cout << *xptrptr << endl; 22 | 23 | // new kelimesi gordugunuz her yer heap memory 24 | 25 | int y = 10; 26 | int* yptr = new int; 27 | *yptr = 10; 28 | 29 | cout << *yptr << endl; 30 | 31 | delete yptr; 32 | 33 | 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Hafta3/array2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | // Operatorler : <<, >>, [], +, -, *, /, ++, --, ||, &&, !, == 7 | // Bitwise operatorler: &, |, ^, ~ (Bit olarak islem yapmak icin) 8 | 9 | 10 | // 1 -> (8 bit diyelim) 00000001 11 | 12 | // 0010101 & 0000101 -> 0000101 13 | // 0010101 | 0000101 -> 0010101 14 | 15 | 16 | // % -> modulus 17 | 18 | 19 | // Alttaki bir global degisken ornegi 20 | int arr[7] = {3, 2, 1, 7, 12, 10, 11}; 21 | 22 | int main() 23 | { 24 | for (int i=0; i<7; i++) 25 | { 26 | if (arr[i] % 2 != 0) 27 | cout << arr[i] << ' '; 28 | } 29 | 30 | 31 | cout << endl; 32 | 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Hafta4/two_dimensional_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | #define SIZE(arr) sizeof(arr)/sizeof(arr[0]) 6 | 7 | 8 | int main() 9 | { 10 | int arr[] = {1,2,3}; 11 | int twoDimArr[3][3] = {{1,2,3}, 12 | {4,5,6}, 13 | {7,8,9}}; 14 | 15 | int s = SIZE(twoDimArr); 16 | 17 | for (int i=0; i < s; i++) 18 | { 19 | for (int j=0; j v; 25 | 26 | // a = [], a.append(3) 27 | 28 | v.push_back(10); 29 | v.push_back(20); 30 | 31 | for (auto i : v) 32 | cout << i << ' '; 33 | 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Hafta4/recursion_1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int faktoriyel(int n) 6 | { 7 | if (n == 1) 8 | return n; 9 | 10 | return n * faktoriyel(n-1); 11 | } 12 | 13 | int toplam(int n) 14 | { 15 | if (n == 1) 16 | return n; 17 | 18 | return n + toplam(n-1); 19 | } 20 | 21 | int ikiUzeri(int n) 22 | { 23 | if (n == 0) 24 | return 1; 25 | 26 | return 2 * ikiUzeri(n-1); 27 | } 28 | 29 | 30 | int main() 31 | { 32 | cout << "Faktoriyelini bulunmasini istediginiz sayiyi girin" << endl; 33 | int n; cin >> n; 34 | 35 | cout << faktoriyel(n) << endl; 36 | cout << toplam(n) << endl; 37 | cout << ikiUzeri(n) << endl; 38 | 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Hafta1/strings.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | // Buraya not ekliyorum 9 | 10 | 11 | string compec = "Merhaba \nCompec 2021!"; 12 | 13 | // cout << compec; 14 | 15 | //cout << "Merhaba Compec 2021!"; 16 | 17 | 18 | // compec = "Merhaba\n"; 19 | // compec = compec + "Compec 2021"; 20 | 21 | 22 | string compec1 = "Merhaba"; 23 | const char* compecC = "Merhaba"; 24 | string compec2 = "Compec 2021!"; 25 | 26 | // cout << compec1 << endl << compec2; 27 | 28 | // cout << compec1[0]; 29 | 30 | //printf ("Characters: %c %c \n", 'a', 'b'); 31 | //printf ("Compec Ilk Karakter: %c \n", compec1[3]); 32 | printf("%s", compecC); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Hafta5/2dvectors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | vector> v; 9 | 10 | v.push_back(vector(3,0)); 11 | v.push_back(vector{1,2,3}); 12 | v.push_back(vector(5, -1)); 13 | 14 | 15 | /* 16 | 0 0 0 17 | 1 2 3 18 | -1 -1 -1 -1 -1 19 | */ 20 | 21 | for (int i=0; i> v1(5, vector(5, 11)); 29 | 30 | for (int i=0; i 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int arr[] = {1,3,2,2,1,1,4,6,7,1,1,2,3,4,5,7,78,10}; 8 | 9 | // sizeof -> degiskenin BYTE olarak boyutunu soyler (1 byte = 8 bit) 10 | int x = 32; 11 | 12 | cout << sizeof(x) << endl; 13 | 14 | char c = 'A'; 15 | 16 | cout << sizeof(c) << endl; 17 | 18 | 19 | cout << sizeof(arr) << endl; 20 | 21 | int n = sizeof(arr)/sizeof(arr[0]); 22 | 23 | cout << n << endl; 24 | 25 | for (int i=0; i son elemana ulasirsiniz. C++ ta kesinlikle yok 32 | // arr[sizeof(arr)/sizeof(arr[0]) - 1] -> son elemani verir 33 | 34 | cout << arr[n-1] << endl; 35 | 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Hafta2/for-1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | cout << "Lutfen bir sayi girin " << endl; 8 | int sayi; 9 | cin >> sayi; 10 | 11 | int i; 12 | for (i = 0; i 2 | using namespace std; 3 | 4 | 5 | 6 | int topla(int x, int y) 7 | { 8 | float z = x + y + 0.99; 9 | 10 | //Parametre otomatik olarak inte donusturulur 11 | // yani return (int) z olarak degistirilir 12 | return z; 13 | } 14 | 15 | float topla2(float x, float y) 16 | { 17 | // Burada donusturme yapilir, return de yapilmaz 18 | int z = x + y + 0.99; 19 | 20 | return z; 21 | } 22 | 23 | // void -> NON-TYPE 24 | 25 | int main() 26 | { 27 | int a, b; 28 | 29 | cout << "Lutfen iki sayi girin" << endl; 30 | cin >> a >> b; 31 | 32 | 33 | // Fonksiyon yazacagiz. Kullanicidan iki sayi alip bunlarin toplamini donecek 34 | 35 | //cout << topla(x, y) << endl;; 36 | cout << topla(a, b) << endl; 37 | cout << topla2(1.1, 5.5) << endl; 38 | 39 | 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Hafta3/palindromestring-fonksiyonlar3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | // Palindrome string -> bastan ve sondan okunusu ayni olan stringlere palindrome string denir 6 | 7 | // Ornek : aba, abcba, aabb 8 | 9 | bool isPalindrome(string s) 10 | { 11 | // stringin boyutunun yarisini alin. sol yari ve sag yariyi teker teker kiyaslayarak devam et 12 | 13 | 14 | for (int i=0; i 0, boyut = 5, 0 - size-i-1 -> 5-0-1 -> 4 17 | // 0 4 18 | // 1 3 19 | if (s[i] != s[s.size()-i-1]) 20 | return false; 21 | } 22 | 23 | return true; 24 | } 25 | 26 | // aabbc 27 | // abcba 28 | 29 | int main() 30 | { 31 | cout << "bakilmasi istenen stringi girin" << endl; 32 | 33 | string s; cin >> s; 34 | 35 | 36 | cout << isPalindrome(s) << endl; 37 | 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Hafta4/pointer3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | // Fonksiyonlarin icine her zaman kopyalari gonderilir. 6 | // Siz degiskeni ne kadar degistirseniz bile, fonksiyonun icinde kalir. Dis kisima hic bir sey yansimaz 7 | void degis(int a, int b) 8 | { 9 | int tmp = a; 10 | a = b; 11 | b = tmp; 12 | } 13 | 14 | void degis(int* a, int* b) 15 | { 16 | int tmp = *a; 17 | *a = *b; 18 | *b = tmp; 19 | } 20 | 21 | 22 | 23 | int main() 24 | { 25 | // Fonksiyon 2 eleman alicak (a,b) sonra bunlari a = b ve b = a olacak sekilde degistirecek 26 | int a = 5, b = 3; 27 | 28 | cout << a << ' ' << b << endl; 29 | 30 | degis(a, b); 31 | 32 | cout << a << ' ' << b << endl; 33 | 34 | int* aptr = &a, *bptr = &b; 35 | degis(aptr, bptr); 36 | 37 | swap(a, b); 38 | 39 | cout << a << ' ' << b << endl; 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Hafta6/Class/class-2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | class Employee 6 | { 7 | public: 8 | int yas; 9 | string isim, soyisim; 10 | 11 | // 1.yontem: member initializer list 12 | Employee(string isim, string soyisim, int yas):isim(isim), soyisim(soyisim), yas(yas) 13 | {} 14 | 15 | void printEmployeeInfo() 16 | { 17 | cout << isim << ' ' << soyisim << endl << yas << endl; 18 | } 19 | 20 | static void printSomething() 21 | { 22 | cout << "BIR SEYLER YAPIYORUZ" << endl; 23 | } 24 | }; 25 | 26 | 27 | 28 | 29 | int main() 30 | { 31 | Employee employee = Employee("Ahmet", "Ozdemir", 25); 32 | // Farkli yazim yontemleri 33 | // Employee employee1; 34 | /*employee.isim = "Ahmet"; 35 | employee.soyisim = "Ozdemir"; 36 | employee.yas = 25;*/ 37 | 38 | employee.printEmployeeInfo(); 39 | Employee::printSomething(); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Hafta6/Class/class-1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | struct Employee 7 | { 8 | int yas; 9 | string isim, soyisim; 10 | }; typedef struct Employee Employee; 11 | 12 | 13 | int main() 14 | { 15 | Employee employee1; 16 | 17 | employee1.isim = "Ahmet"; 18 | employee1.soyisim = "Ozdemir"; 19 | employee1.yas = 25; 20 | 21 | // cout << employee1.isim << ' ' << employee1.soyisim << endl << employee1.yas << endl; 22 | 23 | Employee employee2; 24 | 25 | 26 | cin >> employee2.isim >> employee2.soyisim >> employee2.yas; 27 | 28 | // cout << employee2.isim << ' ' << employee2.soyisim << endl << employee2.yas << endl; 29 | 30 | Employee emp[] = {employee1, employee2}; 31 | vector v = {employee1, employee2}; 32 | 33 | for (auto i : v) 34 | cout << i.isim << ' ' << i.soyisim << endl << i.yas; 35 | 36 | 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Hafta3/asalsayi-fonksiyonlar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | string asalmiDegilmi(int n) 7 | { 8 | if (n == 1) 9 | return "HAYIR"; 10 | else 11 | { 12 | //optimize edilmemis 13 | //for (int i=2; i> n; 40 | 41 | cout << asalmiDegilmi(n) << endl; 42 | 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Hafta2/input1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | /*cout << "Lutfen isminizi giriniz" << endl; 7 | 8 | // alttaki degisken NULL value 9 | string isim; 10 | 11 | cin >> isim; 12 | 13 | cout << "Merhaba, " << isim << endl; 14 | 15 | int yas; 16 | 17 | cout << "Lutfen yasinizi girer misiniz?" << endl; 18 | 19 | cin >> yas; 20 | 21 | cout << "Merhaba, " << isim << " ve yasiniz " << yas << endl; 22 | */ 23 | // float -> 8 bitlik ondalikli sayi 24 | // double -> 12 bitlik ondalikli sayi 25 | float pi; 26 | 27 | cout << "Pi'nin kac hanesini biliyorsaniz lutfen girin." << endl; 28 | 29 | cin >> pi; 30 | 31 | cout.precision(8); 32 | cout << fixed << "Sizin bildiginiz pi'nin degeri " << pi << endl; 33 | 34 | char a; 35 | 36 | cout << "Lutfen herhangi bir karakter giriniz." << endl; 37 | 38 | cin >> a; 39 | 40 | cout << a << endl; 41 | 42 | 43 | 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Hafta3/fonksiyonlar2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | #define SIZE(arr) sizeof(arr)/sizeof(arr[0]) 7 | 8 | 9 | // Arrayi fonksiyona yollarken kesinlikle boyutunuda ekstra parametre olarak yollayin 10 | int topla(int arr[], int n) 11 | { 12 | // Arrayler fonksiyon icinde olsa bile bir elemani degistirildiginde main fonksiyondada o eleman degisir 13 | //arr[0] = -100000; 14 | 15 | /*for (int i=0; i 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | int arr2d[3][3] = {{1, 2, 3}, 9 | {4, 5, 6}, 10 | {7, 8, 9}}; 11 | 12 | int arr3d[3][3][2] = {{{1,2}, 13 | {4,5}, 14 | {6,7,}}, 15 | {{8,9}, 16 | {10,11}, 17 | {12,13}}, 18 | {{14,15}, 19 | {16,17}, 20 | {18,19}}}; 21 | 22 | cout << arr2d[0][2] << endl; 23 | cout << arr2d[1][1] << endl; 24 | 25 | /*for (int i=0; i<3; i++) 26 | { 27 | for (int j=0; j<3; j++) 28 | { 29 | cout << arr2d[i][j] << ' '; 30 | } 31 | cout << endl; 32 | }*/ 33 | 34 | for (int i=0; i<3; i++) 35 | { 36 | for (int j=0; j<3; j++) 37 | { 38 | for (int k=0; k<2; k++) 39 | { 40 | cout << arr3d[i][j][k] << ' '; 41 | } 42 | cout << endl; 43 | } 44 | cout << endl; 45 | } 46 | 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Hafta2/if-else2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int x; 8 | cout << "Lutfen bir sayi girin:" << endl; 9 | cin >> x; 10 | 11 | // Eger sayimiz 10'dan buyukse veya 2 ye esit ise veya -2 ye esit ise "Evet" degil ise "Hayir" yazdirin. 12 | 13 | if (x > 10 || x == 2 || x == -2) 14 | { 15 | cout << "Evet" << endl; 16 | } 17 | else 18 | { 19 | cout << "Hayir" << endl; 20 | } 21 | 22 | // Uc tane sayimiz olsun. Ilk sayimiz 10'dan buyuk ise VE ikinci sayimiz ucuncu sayimiza esit ise veya 3.sayimiz 1.sayimiza esitse "evet" yazdirin, degil ise hayir yazdirin. 23 | 24 | int x1, x2, x3; 25 | 26 | cout << "Lutfen 3 tane sayi girin "<< endl; 27 | 28 | cin >> x1 >> x2 >> x3; 29 | 30 | 31 | // 11 32 | if (x1 > 10 && (x2 == x3 || x1 == x3)) 33 | { 34 | cout << "kosul saglandi" << endl; 35 | } 36 | else 37 | { 38 | cout << "Kosul saglanamadi" << endl; 39 | } 40 | 41 | 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Hafta6/Class/class-3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | class Employee 7 | { 8 | int yas; 9 | string isim, soyisim; 10 | 11 | 12 | public: 13 | 14 | Employee(string isim, string soyisim, int yas):isim(isim), soyisim(soyisim), yas(yas) 15 | {} 16 | 17 | 18 | void printSomething() 19 | { 20 | cout << isim << ' ' << soyisim << endl << yas << endl; 21 | } 22 | 23 | // Getter ve Setterlar 24 | string getIsim() const 25 | { 26 | return isim; 27 | } 28 | 29 | // 1.yontem 30 | /*void setIsim(string yeniIsim) 31 | { 32 | isim = yeniIsim; 33 | }*/ 34 | 35 | void setIsim(string isim) 36 | { 37 | this->isim = isim; 38 | } 39 | 40 | void setSoyisim(string soyisim) 41 | { 42 | this->soyisim = soyisim; 43 | } 44 | 45 | string setIsim() const 46 | { 47 | return isim; 48 | } 49 | 50 | }; 51 | 52 | 53 | int main() 54 | { 55 | Employee employee = Employee("Ahmet", "Ozdemir", 25); 56 | 57 | 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /Hafta3/array1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | int main() 7 | { 8 | // Alttaki degisken NULL yani tanimlanmamis durumda 9 | // 40 bytelik yer kapliyor 10 | /*int arr1[10]; 11 | // bizim icin hafizada 40 bytelik bir yer ayir, fakat hic bir sey tanimlama 12 | for (int i=0; i<10; i++) 13 | cout << arr1[i] << ' '; 14 | // Ustteki gibi elemanlar atanmadan ulasilmaya calisirsa program beklenmedik cevaplar verebilir 15 | cout << endl; 16 | return 0;*/ 17 | 18 | // Sadece ilk elemani 1, geri kalan hepsini 0 yapar 19 | // tum veri tipleri icin gecerli, farketmez int, float, string 20 | int arr[10] = {1}; 21 | 22 | for (int i=0; i<10; i++) 23 | cout << arr[i] << ' '; 24 | cout << endl; 25 | 26 | 27 | string arrString[3] = {"Compec"}; 28 | 29 | for (int i=0; i<3; i++) 30 | cout << arrString[i] << ' '; 31 | 32 | if (arrString[1] == "") 33 | cout << "IF IFADEMIZ DOGRU " << endl; 34 | 35 | cout << endl; 36 | 37 | 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Hafta3/stringIslemleri2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int x = 13; 6 | 7 | 8 | void biseylerYazdir() 9 | { 10 | int x = 199; 11 | 12 | cout << x << endl; 13 | //Global olani bastirmak yada eristirmek istiyosan 14 | cout << ::x << endl; 15 | } 16 | 17 | 18 | int main() 19 | { 20 | string isim; 21 | cin >> isim; 22 | 23 | // islower, isupper 24 | 25 | // Iki farkli gosterim 26 | // if (isupper(isim[0])) 27 | if (!islower(isim[0])) 28 | cout << "Ismi dogru girdiniz, isminiz \n" << isim << endl; 29 | else 30 | cout << "Lutfen isminizi bas harfi buyuk olacak sekilde girin" << endl; 31 | 32 | 33 | /*isim[0] = toupper(isim[0]); 34 | 35 | cout << isim << endl;*/ 36 | 37 | 38 | // :: 'nin anlamindan bahsedelim 39 | transform(isim.begin(), isim.begin()+5, isim.begin(), ::toupper); 40 | // transform(isim.begin(), isim.end(), isim.begin(), ::tolower); 41 | 42 | 43 | cout << isim << endl; 44 | 45 | biseylerYazdir(); 46 | 47 | 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /Hafta3/asalcarpanlar-fonksiyonlar2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | void asalCarpanlariBul(int n) 7 | { 8 | int i = 2; 9 | 10 | while (n != 1) 11 | { 12 | if (n % i == 0) 13 | { 14 | cout << i << ' '; 15 | n /= i; 16 | } 17 | else 18 | { 19 | i++; 20 | } 21 | } 22 | } 23 | 24 | void asalCarpanlariBulOptimize(int n) 25 | { 26 | while (n%2 == 0) 27 | { 28 | cout << 2 << ' '; 29 | n /= 2; 30 | } 31 | 32 | // ornek 33 | // 3 5 7 9 34 | // 54 35 | // 2, 27 36 | // 3, 27 -> 9, 9/3, 3 3/3 37 | //for (int i=3; i 2) 48 | cout << n; 49 | } 50 | 51 | 52 | int main() 53 | { 54 | cout << "Lutfen asal carpanlarinin bulunmasini istediginiz bir sayi girin" << endl; 55 | 56 | int n; cin >> n; 57 | 58 | 59 | asalCarpanlariBul(n); 60 | 61 | asalCarpanlariBulOptimize(n); 62 | 63 | 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /Hafta5/vectors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | void printElements(int arr[]) 7 | { 8 | // YANLIS GOSTERIM, int* in sizeini geri doner 9 | int sze = sizeof(arr) / sizeof(arr[0]); 10 | 11 | cout << sze << endl; 12 | 13 | } 14 | 15 | void printElements(vector& v) 16 | { 17 | for (int i=0; i v; 32 | 33 | cout << v.size() << endl; 34 | 35 | 36 | v.push_back(10); 37 | v.push_back(20); 38 | 39 | 40 | cout << v[0] << endl; 41 | cout << v[1] << endl; 42 | 43 | cout << v.size() << endl; 44 | */ 45 | 46 | vector v1(10, -5); 47 | 48 | /*for (auto i : v1) 49 | cout << i << ' '; 50 | 51 | cout << endl;*/ 52 | 53 | /*for (int i=0; i 2 | #include 3 | using namespace std; 4 | 5 | 6 | // 1 < kupkok(n) < sqrt(n) < logn < n < n*logn < n**2 < n**3 ... < 2**n < 3**n .... < n**n (n!) 7 | 8 | void bubbleSort(int arr[], int n) 9 | { 10 | // O(n*n == n**2) 11 | for (int i=0; i arr[j+1]) 16 | swap(arr[j], arr[j+1]); 17 | } 18 | } 19 | } 20 | 21 | void bubbleSortRecursive(int arr[], int n) 22 | { 23 | if (n == 1) 24 | return; 25 | 26 | for (int i=0; i arr[i+1]) 29 | swap(arr[i], arr[i+1]); 30 | } 31 | 32 | bubbleSortRecursive(arr, n-1); 33 | } 34 | 35 | 36 | 37 | int main() 38 | { 39 | srand(1); 40 | 41 | int arr[20]; 42 | 43 | for (int i=0; i<20; i++) 44 | arr[i] = rand() % 20; 45 | 46 | for (int i=0; i<20; i++) 47 | cout << arr[i] << ' '; 48 | 49 | cout << endl; 50 | 51 | bubbleSortRecursive(arr, 20); 52 | 53 | for (int i=0; i<20; i++) 54 | cout << arr[i] << ' '; 55 | 56 | cout << endl; 57 | 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /Hafta6/Class/linked-list-1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | class Node 7 | { 8 | public: 9 | int data; 10 | Node* next; 11 | 12 | Node(int data) 13 | { 14 | this->data = data; 15 | this->next = NULL; 16 | } 17 | }; 18 | 19 | void printLinkedList(Node* head) 20 | { 21 | while (head != NULL) 22 | { 23 | cout << head->data << ' '; 24 | head = head->next; 25 | } 26 | } 27 | 28 | void printLinkedListRecursive(Node* head) 29 | { 30 | if (head == NULL) 31 | return; 32 | 33 | 34 | cout << head->data << ' '; 35 | 36 | printLinkedListRecursive(head->next); 37 | } 38 | 39 | 40 | int main() 41 | { 42 | Node* head = new Node(40); 43 | Node* second = new Node(32); 44 | Node* third = new Node(98); 45 | Node* fourth = new Node(38); 46 | Node* fifth = new Node(47); 47 | Node* sixth = new Node(26); 48 | 49 | head->next = second; 50 | second->next = third; 51 | third->next = fourth; 52 | fourth->next = fifth; 53 | fifth->next = sixth; 54 | 55 | printLinkedListRecursive(head); 56 | 57 | 58 | delete head, second, third, fourth, fifth, sixth; 59 | 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /Hafta5/fibonacci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | unsigned long long arr[1000]; 7 | 8 | 9 | int fiboRecursive(int n) 10 | { 11 | if (n <= 1) 12 | return n; 13 | return fiboRecursive(n-1) + fiboRecursive(n-2); 14 | } 15 | 16 | 17 | 18 | int fibo(int n) 19 | { 20 | if (n <= 1) 21 | { 22 | arr[n] = n; 23 | return arr[n]; 24 | } 25 | if (arr[n] != -1) 26 | return arr[n]; 27 | 28 | // return fibo(arr, n-1) + fibo(arr, n-2); bunun yerine alttakini kullanip arrayin elemanina atiyoruz 29 | arr[n] = fibo(n-1) + fibo(n-2); 30 | return arr[n]; 31 | } 32 | 33 | 34 | 35 | int main() 36 | { 37 | //Dynamic programming 38 | 39 | cout << "Kac fibonacci sayisinin bulunmak istedigini giriniz" << endl; 40 | int n; cin >> n; 41 | 42 | int arr[n]; 43 | 44 | memset(::arr, -1, sizeof(::arr)); 45 | 46 | clock_t currentTime = time(0); 47 | 48 | /*fibo(n); 49 | 50 | for (int i=0; i 2 | #include 3 | using namespace std; 4 | 5 | 6 | 7 | // 3 2 5 7 8 10 8 | // 2 = key 9 | 10 | void insertionSort(int arr[], int n) 11 | { 12 | for (int i=1; i0; j--) 15 | { 16 | if (arr[j] < arr[j-1]) 17 | swap(arr[j], arr[j-1]); 18 | } 19 | } 20 | } 21 | 22 | void insertionSortCool(int arr[], int n) 23 | { 24 | for (int i=1; i0 && arr[j] < arr[j-1]; j--) 26 | swap(arr[j], arr[j-1]); 27 | } 28 | 29 | 30 | void insertionSortNormal(int arr[], int n) 31 | { 32 | for (int i=1; i=0 && arr[j]>key) 38 | { 39 | arr[j+1] = arr[j]; 40 | j--; 41 | } 42 | arr[j+1] = key; 43 | } 44 | } 45 | 46 | 47 | 48 | 49 | int main() 50 | { 51 | srand(1); 52 | 53 | int arr[10]; 54 | 55 | int n = 10; 56 | 57 | for (int i=0; i<10; i++) 58 | arr[i] = rand() % 15; 59 | 60 | for (auto i : arr) 61 | cout << i << ' '; 62 | cout << endl; 63 | 64 | insertionSortNormal(arr, n); 65 | 66 | for (auto i : arr) 67 | cout << i << ' '; 68 | cout << endl; 69 | 70 | /*for (int i=0, j=10; i<10 && j>0; i++, j--) 71 | { 72 | cout << i << ' ' << j << endl; 73 | }*/ 74 | 75 | 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /Hafta2/if-else1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | cout << "Lutfen yasinizi giriniz:" << endl; 8 | 9 | int yas; 10 | cin >> yas; 11 | 12 | // <, >, <=, >=, == 13 | // =<, => ikiside hatali yazim 14 | 15 | /*if (yas > 17) 16 | { 17 | cout << "Araba kullanmaya yasiniz yeterli." << endl; 18 | } 19 | else 20 | { 21 | cout << "Uzgunum, ehliyet icin yasiniz yeterli degil." << endl; 22 | }*/ 23 | 24 | 25 | // 16 yas -> yaninda ehliyetli biri varken araba kullanabiliyor 26 | // 18 yas -> araba kullanabiliyor 27 | // 21 yas -> alkol alabiliyor 28 | 29 | 30 | // ve -> && (Her 2 ifadeninde dogru olmasi lazim) 31 | // veya -> || (2 ifadeden birinin dogru olmasi yeterli) 32 | 33 | 34 | // Ilk gosterim 35 | /*if (yas < 16) 36 | { 37 | cout << "Hic bir sey kullanamiyorsunuz" << endl; 38 | } 39 | else if (yas >= 16 && yas < 18) 40 | { 41 | cout << "Yaninizda ehliyetli biri varken araba surebilirsiniz" << endl; 42 | } 43 | else if (yas >= 18 && yas < 21) 44 | { 45 | cout << "Kendi basiniza araba surebilirsiniz" << endl; 46 | } 47 | else if (yas >= 21) 48 | { 49 | cout << "Hem alkol alabilirsiniz hemde araba kullanabilirsiniz." << endl; 50 | }*/ 51 | 52 | 53 | if (yas < 16) 54 | { 55 | cout << "Hic bir sey kullanamiyorsunuz" << endl; 56 | } 57 | else if (yas < 18) 58 | { 59 | cout << "Yaninizda ehliyetli biri varken araba surebilirsiniz" << endl; 60 | } 61 | else if (yas < 21) 62 | { 63 | cout << "Kendi basiniza araba surebilirsiniz" << endl; 64 | } 65 | else 66 | { 67 | cout << "Hem alkol alabilirsiniz hemde araba kullanabilirsiniz." << endl; 68 | } 69 | 70 | 71 | 72 | 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /Hafta5/taskagitmakas.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | int main() 9 | { 10 | srand(time(NULL)); 11 | cout << "Tas kagit makas oyununa hosgeldiniz" << endl; 12 | 13 | 14 | while (true) 15 | { 16 | int rastgeleSayi = rand() % 3; 17 | 18 | cout << "Lutfen tercihinizi yapin:\n 1- Tas\n 2- Kagit\n 3- Makas" << endl; 19 | 20 | string kullaniciTercihi; 21 | cin >> kullaniciTercihi; 22 | 23 | transform(kullaniciTercihi.begin(), kullaniciTercihi.end(), kullaniciTercihi.begin(), ::tolower); 24 | 25 | 26 | if (kullaniciTercihi != "tas" && kullaniciTercihi != "makas" && kullaniciTercihi != "kagit") 27 | { 28 | cout << "Lutfen dogru bir secenek yazin." << endl; 29 | continue; 30 | } 31 | else 32 | { 33 | // 0 == tas, 1 == makas, 2 == kagit 34 | if (rastgeleSayi == 0 && kullaniciTercihi == "makas") 35 | { 36 | cout << "Bilgisayar tas secmisti. Kaybettiniz." << endl; 37 | } 38 | else if (rastgeleSayi == 0 && kullaniciTercihi == "kagit") 39 | { 40 | cout << "Bilgisayar tas secmisti. Kazandiniz." << endl; 41 | } 42 | else if (rastgeleSayi == 0 && kullaniciTercihi == "tas") 43 | { 44 | cout << "Bilgisayar tas secmisti. Berabere." << endl; 45 | } 46 | else if (rastgeleSayi == 1 && kullaniciTercihi == "kagit") 47 | { 48 | cout << "Bilgisayar makas secmisti. Kaybettiniz." << endl; 49 | } 50 | else if (rastgeleSayi == 1 && kullaniciTercihi == "kagit") 51 | { 52 | cout << "Bilgisayar tas secmisti. Kazandiniz." << endl; 53 | } 54 | else if (rastgeleSayi == 1 && kullaniciTercihi == "makas") 55 | { 56 | cout << "Bilgisayar makas secmisti. Berabere." << endl; 57 | } 58 | else if (rastgeleSayi == 2 && kullaniciTercihi == "tas") 59 | { 60 | cout << "Bilgisayar kagit secmisti. Kaybettiniz." << endl; 61 | } 62 | else if (rastgeleSayi == 2 && kullaniciTercihi == "kagit") 63 | { 64 | cout << "Bilgisayar kagit secmisti. Berabere." << endl; 65 | } 66 | else 67 | { 68 | cout << "Bilgisayar kagit secmisti. Kazandiniz." << endl; 69 | } 70 | } 71 | } 72 | 73 | return 0; 74 | } 75 | --------------------------------------------------------------------------------