#include <stdio.h>Okey..Ini dia Build and Run.
int isprima(int x);
float pangkat (float basis, int n);
float kpk(int x, int y);
float fpb(int x, int y);
main()
{
float X,Y,hasil;
int A,B,pilihan;
int Z;
char ulangi;
do{
printf("Pilihan operasi: ");
printf("\n1. X + Y\n2. X - Y\n3. X x Y\n4. X / Y");
printf("\n5. X Pangkat Y\n6. KPK X dan Y\n7. FPB X dan Y\n8. Cek prima X");
printf("\nPilihan anda: ");scanf("%d",&pilihan);
switch(pilihan)
{
case 1:
printf("\nX = ");scanf("%f",&X);
printf("Y = ");scanf("%f",&Y);
hasil = X + Y;
break;
case 2:
printf("\nX = ");scanf("%f",&X);
printf("Y = ");scanf("%f",&Y);
hasil = X - Y;
break;
case 3:
printf("\nX = ");scanf("%f",&X);
printf("Y = ");scanf("%f",&Y);
hasil = X * Y;
break;
case 4:
printf("\nX = ");scanf("%f",&X);
printf("Y = ");scanf("%f",&Y);
hasil = X / Y;
break;
case 5:
printf("\nX = ");scanf("%f",&X);
printf("Y = ");scanf("%d",&B);
hasil = pangkat(X,B);
break;
case 6:
printf("\nX = ");scanf("%d",&A);
printf("Y = ");scanf("%d",&B);
Z = kpk(A,B);
hasil = Z;
break;
case 7:
printf("\nX = ");scanf("%d",&A);
printf("Y = ");scanf("%d",&B);
Z = fpb(A,B);
hasil = Z;
break;
case 8:
printf("\nX = ");scanf("%d",&A);
Z = isprima(A);
if (Z==1)
printf("X adalah bilangan prima\n");
else
printf("X bukan bilangan prima\n");
break;
default:
printf("Pilihan anda salah!!");
}
if((pilihan<=7) && (pilihan>=1))
printf("Hasil = %f",hasil);
printf("\n");
printf("Ulangi operasi (Y/N)? ");
scanf("%s",&ulangi);
}while((ulangi=='Y')||(ulangi=='y'));
}
int isprima(int x)
{
int n,t=1,s;
if ( x < 2 )
{s = 0;}
else
{
for (n=2;t!=0;n++)
{
t = x%n;
}
n--;
if(n==x)
{s = 1;}
else
{s = 0;}
}
return (s);
}
float pangkat (float basis, int n)
{
int i;
float p;
p = 1;
for (i = 1; i <= n; ++i)
p = p* basis;
return p;
}
float kpk(int x, int y)
{
int w=1,n;
int z;
if (x < y)
{
for (n=1; w != 0; n++)
{ z = y * n;
w = z % x;
}
}
else
{
for (n=1; w != 0; n++)
{ z = x * n;
w = z % y;
}
}
return (z);
}
float fpb(int x,int y)
{
int sisabagi;
float hasil;
if(y<=x && x%y==0)
{
return(y);
}
else if(x<y)
{
hasil=fpb(y,x);
return(hasil);
}
else
sisabagi=x%y;
hasil=fpb(y,sisabagi);
return(hasil);
}
Masukan Input
manteb sob sharenya kpn2 saja coba,
BalasHapusmbak sit di side bar sudah saya colek sob :)
dtunggu colekan baliknya dblogq
ke TKP sob,,makasih sudah berkunjung :D
Hapuskurang paham sob, absen malam saja dan bertugas disini , salam 69 :)
BalasHapusposisi kesukaanku pula.. :D
Hapusmuzmet saya sob. gak mudeng blas..wuakakaka
BalasHapustapi mantep tuh artikelnya.
thanks ya sob.. 6^_^9 di malam Natal.
apa iya sob,,lihat aja deh :D
HapusIzin nyimak aja, lagi dikejar waktu ane, kunjungan baliknya yah
BalasHapusokey sob,ke TKP :)
Hapuswahh,,, kya hacker aja .
BalasHapusbukan hacker sob tapi programer hihi ;)
Hapuskepala saya koq muter2 ya sob liat tulisan diatas.. hehehe...
BalasHapustapi mantap banget sob postingan'nya..
Sikat abis 69 disini.. :D
yang muter orangnya apa layarnya? ;;)
Hapus