LA PAA 3 algoritma brute force


contoh coding algoritma brute force
compiler : C++

#include
#include
#include

void prima (),bsort(),kalimatriks();

main()
{
start :
int x;
clrscr();
printf (“\n \t Algoritma Brute Force \n”);
printf (“\n ==========================================”);
printf (“\n \t Pencarian Bilangan Prima”);
printf (“\n \t Sorting Bilangan”);
printf (“\n \t Perkalian Matrix”);
printf (“\n \t Exit “);
printf (“\n ========================================= \n”);
printf (“\n Masukkan Pilihan (1-4) : “);
scanf (“%d”,&x);
if (x<=4)
switch (x)
{
case 1: prima ();
goto start;
case 2: bsort();
goto start;
case 3: kalimatriks();
goto start;
case 4: return 0;
}
else
{
clrscr ();
printf ("\n Anda salah memasukkan nilai ");
printf("\n");
goto start;
}
return 0;
}

void prima ()
{
int bil,j;
clrscr();
printf ("Masukkan Data Yang Ingin Diinput: ");
scanf("%d",&bil);
for(j=2;j0)&&(j%3>0)&&(j%5>0)&&(j%7>0) || (j==2)||(j==3)||(j==5)||(j==7))
printf (“%i “,j);
}
getch();
}

void bsort()
{
int i,j,temp,n,bil[100];
clrscr();
printf (“Masukkan jumlah bilangan: ” );
scanf (“%d”,&n);
for(i=0;i<n;i++)
{
printf ("Bilangan ke-%d \t: ",i+1);
scanf ("%d",&bil[i]);
}
printf ("\n");
for(i=0;ii;j–)
{
if (bil[i] > bil[j])
{
temp = bil[i];
bil[i] = bil[j];
bil[j] = temp;
}
}
}
printf (“Sorting:”);
for(i=0;i<n;i++)
{
printf ("%d",bil[i]);
if (i!= n-1)
{
printf (",");
}
}
getch();
}

void kalimatriks()
{
int i,j,k,temp,ordo,ma[10][10],mb[10][10],mc[10][10];
clrscr();
printf ("Masukkan Ordo Matriks: ");
scanf ("%d",&ordo);
printf ("Matriks A:");
for(i=0;i<ordo;i++)
{
for(j=0;j<ordo;j++)
{
gotoxy((j+1)*5,i+3);
scanf ("%d",&ma[i][j]);
}
}
printf ("\n");
printf ("Matriks B:");
for(i=0;i<ordo;i++)
{
for(j=0;j<ordo;j++)
{
gotoxy((j+1)*5,i+5+ordo);
scanf ("%d",&mb[i][j]);
}
}
for(i=0;i<ordo;i++)
{
for(j=0;j<ordo;j++)
{
temp = 0;
for(k=0;k<ordo;k++)
{
temp += ma[i][k] * mb[k][j];
}
mc[i][j] = temp;
}
}
printf ("\n");
printf ("Hasil MAtriks A * Matriks B: ");
for(i=0;i<ordo;i++)
{
for(j=0;j<ordo;j++)
{
gotoxy((j+1)*5,i+7+ordo*2);
printf ("%d", mc[i][j]);
}
}
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: