Skip to content

Commit 581afee

Browse files
committed
Ders 22
1 parent 7247521 commit 581afee

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

22_practice/main.go

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// 1-) 1 ile 10 arasındaki sayıları if yapısıyla tek - çift olarak yazdırınız.
2+
3+
/* package main
4+
5+
import "fmt"
6+
7+
func main() {
8+
9+
for i := 1; i <= 10; i++ {
10+
11+
if i%2 == 0 {
12+
fmt.Println(i, "çittir")
13+
} else {
14+
fmt.Println(i, "tektir")
15+
}
16+
}
17+
18+
} */
19+
20+
// 2-) for yapısını kullanarak Go'da olmayan while döngüsüne örnek veriniz.
21+
22+
/* package main
23+
24+
import "fmt"
25+
26+
func main() {
27+
28+
x := 0
29+
30+
for x < 10 {
31+
fmt.Println(x)
32+
x++
33+
}
34+
35+
} */
36+
37+
// 3-) Switch fallthrough ifadesini açıklayınız.
38+
39+
/* package main
40+
41+
import "fmt"
42+
43+
func main() {
44+
45+
switch x := 75; {
46+
case x < 20:
47+
fmt.Printf("%d küçüktür 20\n", x)
48+
fallthrough
49+
50+
case x < 50:
51+
fmt.Printf("%d küçüktür 50\n", x)
52+
fallthrough
53+
54+
case x < 100:
55+
fmt.Printf("%d küçüktür 100\n", x)
56+
fallthrough
57+
58+
case x < 200:
59+
fmt.Printf("%d küçüktür 200\n", x)
60+
}
61+
62+
} */
63+
64+
// 4-) Aşağıdaki if döngüsünü daha idiomatic hale getiriniz.
65+
66+
/* package main
67+
68+
import (
69+
"fmt"
70+
)
71+
72+
func main() {
73+
if x := 20; x%2 == 0 {
74+
fmt.Println(x, "çifttir")
75+
} else {
76+
fmt.Println(x, "tektir")
77+
}
78+
} */
79+
80+
/* package main
81+
82+
import "fmt"
83+
84+
func main() {
85+
86+
x := 20
87+
88+
if x%2 == 0 {
89+
fmt.Println(x, "çifttir")
90+
return
91+
}
92+
93+
fmt.Println(x, "tektir")
94+
} */
95+
96+
// 5-) 1 ile 50 arasındaki asal sayıları gösteren bir program yazınız.
97+
98+
package main
99+
100+
import "fmt"
101+
102+
func main() {
103+
104+
var x, y int
105+
106+
for x = 2; x < 50; x++ {
107+
for y = 2; y < (x / y); y++ {
108+
if x%y == 0 {
109+
break
110+
}
111+
}
112+
113+
if y > (x / y) {
114+
fmt.Printf("%d bir asal sayıdır\n", x)
115+
}
116+
}
117+
}

0 commit comments

Comments
 (0)