Günün C Uygulamaları
- October 22, 2012
Bugün yaptığım C uygulamalarının çözümlerini, ne işe yaradıklarını 1 cümleyle belirtip burada toplayayım dedim. Amaçlarından kısaca bahsedip kodları yazarak ilerliyorum.
Yazar kasa programı için ufak bir şablon:
#include <stdio.h>
// Yazar kasa program ornegi
void banana(void){
float x;
printf("Enter weight of Banana: ");
scanf("%f", &x);
printf("Price of 1 kg of Banana: 1.80 TL");
printf("\nTotal price for %.2f kg of Banana: TL %.2f", x, x*1.80);
}
void orange(void){
float x;
printf("Enter weight of Orange: ");
scanf("%f", &x);
printf("Price of 1 kg of Orange: 2.60 TL");
printf("\nTotal price for %.2f kg of Orange: TL %.2f", x, x*2.60);
}
int main(void){
printf("Program basladi!\n");
int secim = 0;
printf("\n======================\n");
printf("Code For Fruits:\n[1] Banana\n[2] Orange");
printf("\n======================\n");
printf("Enter your fruit's code: ");
scanf("%d", &secim);
switch (secim){
case 1:
banana();
break;
case 2:
orange();
break;
default:
printf("Wrong selection, try again!");
}
printf("\n\nProgram bitti!\n");
return 0;
}
Yılda %5 zamlanan kurs ücretini ve toplam ücreti hesaplamak(tamam, kira da hesaplayabiliriz).
#include <stdio.h>
#include <string.h>
int main(void){
printf("Program basladi!\n\n");
char isim[50], numara[10];
int yil;
float ucret = 10000, toplam = 0;
printf("Student name: ");
gets(isim);
printf("ID: ");
gets(numara);
printf("Duration of study: ");
scanf("%d", &yil);
printf("Year Course Fee\n");
while(yil--){
printf("%2d TL %5.2f\n", 5-yil, ucret);
toplam += ucret;
ucret += ucret*0.05;
}
printf("Toplam: %.2f", toplam);
printf("\n\nProgram bitti!\n");
return 0;
}
1’den girilen sayıya kadar olan sayıların toplamı
#include <stdio.h>
int main(void){
printf("Program basladi!\n\n");
int x, sonuc = 0;
printf("Enter the value of n: ");
scanf("%d",&x); x++;
while (x--)
sonuc += x;
printf("\nSonuc: %d",sonuc);
printf("\n\nProgram bitti!\n");
return 0;
}
Kilo-boy oranını çıkaran kod:
#include <stdio.h>
#include <string.h>
int main(void){
char adsoyad[50], status[20];
float w,h, BMI;
printf("Enter your name: ");
gets(adsoyad);
printf("\nEnter your height in meters: ");
scanf("%f",&h);
printf("\nEnter your weight in kilogram: ");
scanf("%f",&w);
BMI = w/(h*h);
if (BMI < 18.5)
strcpy(status, "Underweight");
else if (BMI < 24.9)
strcpy(status, "Normal");
else if (BMI < 29.9)
strcpy(status, "Overweight");
else
strcpy(status, "Obese");
printf("Name: %s Status: %s\n", adsoyad, status);
system("pause");
return 0;
}
Maaş+Primde alınacak toplam paranın hesabı:
#include <stdio.h>
#include <string.h>
int main(void){
char isim[50];
float oran = 0.0,bonus;
int maas, satis;
printf("Name of the person: ");
gets(isim);
printf("Enter Salary: ");
scanf("%d", &maas);
printf("Sold units: ");
scanf("%d", &satis);
printf("\n\n");
gets(isim);
if (satis<100)
oran = 0.0;
else if (satis<=200)
oran = 0.02;
else if(satis <= 300)
oran = 0.04;
else
oran = 0.06;
bonus = maas*oran;
printf("Name: %s", isim);
printf("Salary: %d\nUnits sold: %d\nBonus percent: %.2f %%",maas, satis, 100*oran);
printf("\nBonus: %.2f", oran*maas);
printf("\n#######################\n");
printf("Total: %.2f", oran*maas+maas);
return 0;
}