-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
79 lines (62 loc) · 2.1 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
// Bid struct'i tanimliyoruz
typedef struct {
int teklifveren_no;
double teklif;
} Bid;
// Arttirma struct'ini tanimliyoruz
typedef struct {
Bid *teklifler; // Teklif dizisi
int teklifveren_sayisi; // Teklif veren sayisini tanimladik
} Arttirma;
// Fonksiyon prototiplerimiz
double odemeyi_hesapla(Arttirma a, int kazanan_no);
void acikarttirma(Arttirma a);
int main() {
// Kullanicidan teklif veren kisi sayisini alacak
printf("Teklif Veren Sayisini Giriniz: ");
int teklifveren_sayisi;
scanf("%d", &teklifveren_sayisi);
// Arttirma yapisinin olusturulmasi
Arttirma arttirma;
arttirma.teklifveren_sayisi = teklifveren_sayisi;
arttirma.teklifler = (Bid *)malloc(arttirma.teklifveren_sayisi * sizeof(Bid));
// Kullanicidan teklifleri al
for (int i = 0; i < arttirma.teklifveren_sayisi; i++) {
printf("Teklif Veren #%d:\n", i + 1);
arttirma.teklifler[i].teklifveren_no = i + 1;
printf("Teklif Miktarini Giriniz: ");
scanf("%lf", &arttirma.teklifler[i].teklif);
}
// Acik arttirmanin gerçeklestirilmesi
acikarttirma(arttirma);
// Bellekten ayrilmasi
free(arttirma.teklifler);
return 0;
}
// Odemeyi hesapla fonksiyonu
double odemeyi_hesapla(Arttirma a, int kazanan_no) {
double odeme = 0.0;
for (int i = 0; i < a.teklifveren_sayisi; i++) {
if (i != kazanan_no) {
odeme += a.teklifler[i].teklif;
}
}
return odeme;
}
// Acik arttirma fonksiyonu
void acikarttirma(Arttirma a) {
double enyuksek_teklif = -1.0;
int kazanan_no = -1;
for (int i = 0; i < a.teklifveren_sayisi; i++) {
// Kazanan teklif sahibini belirle
if (a.teklifler[i].teklif > enyuksek_teklif) {
enyuksek_teklif = a.teklifler[i].teklif;
kazanan_no = i;
}
}
// Kazanan teklif sahibini ve ödemeyi göster
printf("Kazanan Teklif Sahibi: %d\n", a.teklifler[kazanan_no].teklifveren_no);
printf("Odeme: %.2f\n", enyuksek_teklif);
}