Contoh program C lagi.

Program ini untuk menghitung. Capek ah jelasinnya. Coba aja sendiri. :hammer

 

 

int pilihan;
float x,y,a,b,c,d,p,q,hasil,var1,var2,var3,var4,var5,var6;

main()
{
puts("Masukkan program yang mau dijalankan : ");
puts("1. x1 = (a-b)/(a+b)");
puts("2. x2 = (a^2+b^2)/(x^2y)");
puts("3. x3 = (ad-(bc/2))/(xy)");
puts("4. x4 = ((pq^2)-(xy))/(a^2b)");
puts("98. Shutdown program");
puts("");
printf("Enter your choice : ");scanf("%i",&pilihan);
execpilihan();
}

execpilihan()
{
if (pilihan==1)
{
clear();
printf("Masukkan nilai a : ");scanf("%f",&a);
printf("Masukkan nilai b : ");scanf("%f",&b);
hasil=(a-b)/(a+b);
printf("Hasil = %.2f",hasil);
}
else if (pilihan==2)
{
clear();
printf("Masukkan nilai a : ");scanf("%f",&a);
printf("Masukkan nilai b : ");scanf("%f",&b);
printf("Masukkan nilai x : ");scanf("%f",&x);
printf("Masukkan nilai y : ");scanf("%f",&y);
hasil=(a*a+b*b)/(x*x*y);
printf("Hasil = %.2f",hasil);
}
else if (pilihan==3)
{
clear();
printf("Masukkan nilai a : ");scanf("%f",&a);
printf("Masukkan nilai b : ");scanf("%f",&b);
printf("Masukkan nilai c : ");scanf("%f",&c);
printf("Masukkan nilai d : ");scanf("%f",&d);
printf("Masukkan nilai x : ");scanf("%f",&x);
printf("Masukkan nilai y : ");scanf("%f",&y);
hasil=(a*d-(b*c/2))/(x*y);
printf("Hasil = %.2f",hasil);
}
else if (pilihan==4)
{
clear();
printf("Masukkan nilai a : ");scanf("%f",&a);
printf("Masukkan nilai b : ");scanf("%f",&b);
printf("Masukkan nilai c : ");scanf("%f",&c);
printf("Masukkan nilai d : ");scanf("%f",&d);
printf("Masukkan nilai x : ");scanf("%f",&x);
printf("Masukkan nilai y : ");scanf("%f",&y);
printf("Masukkan nilai p : ");scanf("%f",&p);
printf("Masukkan nilai q : ");scanf("%f",&q);
hasil=((p*q*q)-(x*y))/(a*a*b);
printf("Hasil = %.2f",hasil);
}
else if (pilihan==98)
{
puts("Program dihentikan.");
}
else
{
puts("Pilihan tidak valid.");
puts("Press any key to continue ...");
clear();
main();
}

}

clear()
{
getch();
system("cls");
}

 

Share Button

Oleh Rinaldo Jonathan

Admin of this site. Artis papan PCB. #zoneRinaldo #Controllerism Studio Demon, Stage Angel, Sleepy Developer, Smoke free. Kalkud SHS 2012, PCR G15.

Tinggalkan Balasan

Verified by ExactMetrics