[su_expand more_text=”Show code” less_text=”Hide code” height=”30″]1) Atur cara 4.1
[/su_expand]
#include <stdio.h>
int main () {
const float pi = 3.1415;
int panjang, lebar, luas_segi4;
float jejari, luas_bulat;
panjang = 12;
jejari = 3.5;
lebar = 3;
printf("Luas bulatan = %f Luas segi4 = %d\n",
pi * jejari * jejari, panjang * lebar );
return 0;
}
[su_expand more_text=”Show code” less_text=”Hide code” height=”30″]2) Atur cara 4.2
[/su_expand]
#include <stdio.h>
int main () {
const float PI = 3.1415;
double jejari, luas, ukurlilit;
printf("Masukkan jejari bagi bulatan : ");
scanf("%lf", &jejari);
luas = PI*jejari*jejari;
ukurlilit = 2*PI*jejari;
printf("Jejari bulatan ialah %0.2f\n", jejari);
printf("Luas bulatan ialah %0.2f\n", luas);
printf("Ukurlilit bulatan ialah %0.2f", ukurlilit);
return 0;
}
[su_expand more_text=”Show code” less_text=”Hide code” height=”30″]3) Atur cara 4.3
[/su_expand]
#include <stdio.h>
int main ()
{
char bandar[30];
printf("Masukkan nama bandar >> ");
gets(bandar); /*baca rentetan*/
printf("Selamat Datang ke ");
puts(bandar); /*cetak rentetan*/
return 0;
}
[su_expand more_text=”Show code” less_text=”Hide code” height=”30″]4) Atur cara 4.4
[/su_expand]
#include <stdio.h>
int main(void)
{
char namastor[30], failLaporan[12];
char kompA, kompB, kompC;
int bilkompA, bilkompB, bilkompC;
float harga1kompA, harga1kompB, harga1kompC,
nilaistok, purataharga;
FILE *stor, *laporan;
stor = fopen("stor12.dat", "r");
printf("Masukkan nama fail laporan > ");
gets(failLaporan);
laporan = fopen(failLaporan, "w");
fgets(namastor,30,stor);
kompA = fgetc(stor); kompB = fgetc(stor); kompC = fgetc(stor);
fscanf(stor,"%d %f", &bilkompA, &harga1kompA);
fscanf(stor,"%d %f", &bilkompB, &harga1kompB);
fscanf(stor,"%d %f", &bilkompC, &harga1kompC);
nilaistok = (bilkompA*harga1kompA) + (bilkompB*harga1kompB)+
(bilkompC*harga1kompC);
purataharga= (harga1kompA + harga1kompB +harga1kompC)/3;
fprintf(laporan,"Laporan Bulanan Stor ");
fputs(namastor, laporan);
fprintf(laporan,"\nKod Komponen\tBil\t\tHarga\n");
fprintf(laporan,"\t%c\t\t\t%d\t\t%0.2f\n", kompA, bilkompA,
harga1kompA);
fprintf(laporan,"\t%c\t\t\t%d\t\t%0.2f\n", kompB, bilkompB,
harga1kompB);
fprintf(laporan,"\t%c\t\t\t%d\t\t%0.2f\n", kompC, bilkompC,
harga1kompC);
fprintf(laporan,"\nNilai stok %0.2f ", nilaistok);
fprintf(laporan,"\nPurata harga satu komponen %0.2f", purataharga);
fclose(stor);
fclose(laporan);
return 0;
}